From 637d0ffc74ab20ed6909ce98f20db07f9d91be78 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 2 Feb 2021 09:52:50 +0100 Subject: [PATCH] confirmation dialog added. --- src/main.rs | 20 ++++++++++++++++++++ src/pocketbook.rs | 8 +++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 12d58b7..153c9fb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -451,6 +451,24 @@ fn fix_db_entries(tx: &Transaction, book_entries: &Vec) -> Statistics } fn main() { + if cfg!(target_arch = "arm") { + let res = pocketbook::dialog( + pocketbook::Icon::None, + "PocketBook has sometimes problems parsing metadata.\n\ + This app tries to fix some of these issues.\n\ + (Note: The database file explore-3.db will be altered!)\n\ + \n\ + Please be patient - this might take a while.\n\ + You will see a blank screen during the process.\n\ + \n\ + Proceed?", + &["Cancel", "Yes"], + ); + if res == 1 { + return; + } + } + let mut conn = Connection::open("/mnt/ext1/system/explorer-3/explorer-3.db").unwrap(); conn.execute("PRAGMA foreign_keys = 0", NO_PARAMS).unwrap(); @@ -465,6 +483,7 @@ fn main() { pocketbook::dialog( pocketbook::Icon::Info, "The database seems to be ok.\nNothing had to be fixed.", + &["OK"], ); } else { pocketbook::dialog( @@ -473,6 +492,7 @@ fn main() { "Authors fixed: {}\nBooks cleaned from DB: {}", &stat.authors_fixed, &stat.ghost_books_cleaned ), + &["OK"], ); } } else { diff --git a/src/pocketbook.rs b/src/pocketbook.rs index 7cbc894..a56c215 100644 --- a/src/pocketbook.rs +++ b/src/pocketbook.rs @@ -12,7 +12,7 @@ pub enum Icon { WLan, } -pub fn dialog(icon: Icon, text: &str) { +pub fn dialog(icon: Icon, text: &str, buttons: &[&str]) -> i32 { let iconstr = match icon { Icon::None => "0", Icon::Info => "1", @@ -22,8 +22,10 @@ pub fn dialog(icon: Icon, text: &str) { Icon::WLan => "5", }; - Command::new(DIALOG_PATH) - .args(&[iconstr, "", text, "OK"]) + let res = Command::new(DIALOG_PATH) + .args([&[iconstr, "", text], buttons].concat()) .output() .unwrap(); + + res.status.code().unwrap_or(-1) }