From 908c14a5bce7317d470d3626c0ec614557d1f372 Mon Sep 17 00:00:00 2001 From: Reyk Floeter Date: Sun, 1 Dec 2019 03:08:19 +0000 Subject: [PATCH] Use GTK dialog (requires zenity) --- Cargo.toml | 1 + src/server.rs | 42 ++++++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ead8f42..c16f2ba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" [dependencies] bubblebabble = "0.1" derive_more = "0.99" +dialog = "0.2.1" dirs = "2.0" env_logger = "0.7" futures = "0.3" diff --git a/src/server.rs b/src/server.rs index 4915ae7..60d0619 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,10 +13,10 @@ // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. use crate::Config; +use dialog::{backends::Zenity, DialogBox}; use std::{ io::{Error, ErrorKind, Result}, path::{PathBuf, MAIN_SEPARATOR}, - process::Command, }; use tokio::{ fs::{remove_file, File}, @@ -119,6 +119,29 @@ pub(crate) async fn run(config: Config) -> Result<()> { return; } + // Print dialog + if !dont_ask { + let mut zenity = Zenity::new(); + zenity.set_icon("question"); + zenity.set_width(360); + let choice = dialog::Question::new(&format!( + "Do you want to accept\n{}\n({} bytes)?", + filename.display(), + file_size + )) + .title("Yodle!") + .show_with(&zenity) + .expect("Could not display dialog box"); + if choice != dialog::Choice::Yes { + info!( + "{} failed: rejected {}", + peer_addr, + filename.file_name().as_ref().unwrap().to_string_lossy() + ); + return; + } + } + debug!( "{} status: receiving {} ({} bytes)", peer_addr, @@ -126,23 +149,6 @@ pub(crate) async fn run(config: Config) -> Result<()> { file_size ); - if !dont_ask { - match Command::new("ssh-askpass") - .arg(&format!( - "Yo! Do you want to accept {} ({} bytes)?", - filename.display(), - file_size - )) - .output() - { - Ok(output) if output.status.success() => {} - _ => { - info!("{} failed: rejected file", peer_addr); - return; - } - } - } - // Create output file let file = match File::create(&filename).await { Ok(f) => f,