Use GTK dialog (requires zenity)

This commit is contained in:
reykfloeter 2019-12-01 03:08:19 +00:00
parent 90aea947e1
commit 908c14a5bc
2 changed files with 25 additions and 18 deletions

View file

@ -7,6 +7,7 @@ edition = "2018"
[dependencies] [dependencies]
bubblebabble = "0.1" bubblebabble = "0.1"
derive_more = "0.99" derive_more = "0.99"
dialog = "0.2.1"
dirs = "2.0" dirs = "2.0"
env_logger = "0.7" env_logger = "0.7"
futures = "0.3" futures = "0.3"

View file

@ -13,10 +13,10 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use crate::Config; use crate::Config;
use dialog::{backends::Zenity, DialogBox};
use std::{ use std::{
io::{Error, ErrorKind, Result}, io::{Error, ErrorKind, Result},
path::{PathBuf, MAIN_SEPARATOR}, path::{PathBuf, MAIN_SEPARATOR},
process::Command,
}; };
use tokio::{ use tokio::{
fs::{remove_file, File}, fs::{remove_file, File},
@ -119,6 +119,29 @@ pub(crate) async fn run(config: Config) -> Result<()> {
return; 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!( debug!(
"{} status: receiving {} ({} bytes)", "{} status: receiving {} ({} bytes)",
peer_addr, peer_addr,
@ -126,23 +149,6 @@ pub(crate) async fn run(config: Config) -> Result<()> {
file_size 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 // Create output file
let file = match File::create(&filename).await { let file = match File::create(&filename).await {
Ok(f) => f, Ok(f) => f,