Pocketbook dialog added.

This commit is contained in:
Martin Brodbeck 2021-01-29 12:47:33 +01:00
parent 1116a93290
commit 049cd06b65
2 changed files with 48 additions and 2 deletions

View file

@ -1,3 +1,5 @@
mod pocketbook;
use rusqlite::{named_params, Connection, Result, NO_PARAMS}; use rusqlite::{named_params, Connection, Result, NO_PARAMS};
use std::error::Error; use std::error::Error;
use std::fs::File; use std::fs::File;
@ -105,6 +107,8 @@ struct BookEntry {
} }
fn main() { fn main() {
let mut authors_fixed = 0;
let mut conn = Connection::open("/mnt/ext1/system/explorer-3/explorer-3.db").unwrap(); let mut conn = Connection::open("/mnt/ext1/system/explorer-3/explorer-3.db").unwrap();
let tx = conn.transaction().unwrap(); let tx = conn.transaction().unwrap();
{ {
@ -133,8 +137,6 @@ fn main() {
} }
} }
//println!("Number of entries found: {}", bookentries.len());
for entry in bookentries { for entry in bookentries {
let file = File::open(entry.filepath.as_str()); let file = File::open(entry.filepath.as_str());
let file = match file { let file = match file {
@ -154,9 +156,24 @@ fn main() {
.unwrap(); .unwrap();
stmt.execute_named(named_params![":file_as": file_as, ":book_id": entry.id]) stmt.execute_named(named_params![":file_as": file_as, ":book_id": entry.id])
.unwrap(); .unwrap();
authors_fixed = authors_fixed + 1;
} }
} }
} }
} }
tx.commit().unwrap(); tx.commit().unwrap();
if cfg!(target_arch = "arm") {
if authors_fixed == 0 {
pocketbook::dialog(
pocketbook::Icon::Info,
"The database seems to be ok.\nNothing had to be fixed.",
);
} else {
pocketbook::dialog(
pocketbook::Icon::Info,
&format!("Authors fixed: {}", &authors_fixed),
);
}
}
} }

29
src/pocketbook.rs Normal file
View file

@ -0,0 +1,29 @@
use std::process::Command;
static DIALOG_PATH: &str = "/ebrmain/bin/dialog";
#[allow(dead_code)]
pub enum Icon {
None = 0,
Info,
Question,
Attention,
X,
WLan,
}
pub fn dialog(icon: Icon, text: &str) {
let iconstr = match icon {
Icon::None => "0",
Icon::Info => "1",
Icon::Question => "2",
Icon::Attention => "3",
Icon::X => "4",
Icon::WLan => "5",
};
Command::new(DIALOG_PATH)
.args(&[iconstr, "", text, "OK"])
.output()
.unwrap();
}