Use env_logger and debug! instead of println!
This commit is contained in:
17
src/cache.rs
17
src/cache.rs
@@ -1,5 +1,6 @@
|
||||
use glib::timeout_future;
|
||||
use gtk::gdk::Texture;
|
||||
use log::debug;
|
||||
use poppler::Document;
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
@@ -34,7 +35,7 @@ impl PageCache {
|
||||
}
|
||||
|
||||
pub fn cache_pages(&mut self, page_numbers: Vec<usize>, area_height: i32) {
|
||||
println!("Caching pages {:?}", page_numbers);
|
||||
debug!("Caching pages {:?}", page_numbers);
|
||||
let begin_of_cashing = Instant::now();
|
||||
for page_number in page_numbers {
|
||||
if self.pages.contains_key(&page_number) {
|
||||
@@ -52,7 +53,7 @@ impl PageCache {
|
||||
}
|
||||
}
|
||||
}
|
||||
println!(
|
||||
debug!(
|
||||
"done caching in {}ms",
|
||||
begin_of_cashing.elapsed().as_millis()
|
||||
);
|
||||
@@ -74,7 +75,7 @@ impl PageCache {
|
||||
}
|
||||
|
||||
fn process_command(&mut self, command: CacheCommand) -> Option<CacheResponse> {
|
||||
println!("Processing command: {:?}...", command);
|
||||
debug!("Processing command: {:?}...", command);
|
||||
match command {
|
||||
CacheCommand::CachePages { pages, area_height } => {
|
||||
self.cache_pages(pages, area_height);
|
||||
@@ -82,9 +83,9 @@ impl PageCache {
|
||||
}
|
||||
CacheCommand::GetCurrentTwoPages { page_left_number } => {
|
||||
if let Some(page_left) = self.get_page(page_left_number) {
|
||||
println!("got left page");
|
||||
debug!("got left page");
|
||||
if let Some(page_right) = self.get_page(page_left_number + 1) {
|
||||
println!("got right page");
|
||||
debug!("got right page");
|
||||
Some(CacheResponse::TwoPagesRetrieved {
|
||||
page_left,
|
||||
page_right,
|
||||
@@ -93,7 +94,7 @@ impl PageCache {
|
||||
Some(CacheResponse::SinglePageRetrieved { page: page_left })
|
||||
}
|
||||
} else {
|
||||
println!("did not get any page");
|
||||
debug!("did not get any page");
|
||||
// TODO: if page left was not empty, this could be because page turning was too quick.
|
||||
// In this case, just not rendering the current page is okay, but when no more render requests are available, one would want to wait for the caching
|
||||
None
|
||||
@@ -136,9 +137,9 @@ where
|
||||
while let Ok(command) = command_receiver.recv().await {
|
||||
if let Some(response) = cache.process_command(command) {
|
||||
// response_sender.send_blocking(response).unwrap();
|
||||
println!("Command processed, activating receiver....");
|
||||
debug!("Command processed, activating receiver....");
|
||||
receiver(response);
|
||||
println!("receiver done");
|
||||
debug!("receiver done");
|
||||
}
|
||||
|
||||
// Add delay to tell gtk to give rendering priority
|
||||
|
@@ -3,6 +3,7 @@ use std::rc::Rc;
|
||||
use cairo::{Context, ImageSurface};
|
||||
use glib::Bytes;
|
||||
use gtk::gdk::Texture;
|
||||
use log::debug;
|
||||
use poppler::Page;
|
||||
|
||||
pub fn draw_pages_to_texture(pages: &[Rc<Page>], area_height: i32) -> Texture {
|
||||
@@ -52,7 +53,7 @@ fn draw_pages(pages: &[Rc<Page>], context: &Context, area_width: i32, area_heigh
|
||||
let scale = height_to_scale_to / page_height;
|
||||
let scaled_width = page_width * scale;
|
||||
|
||||
println!(
|
||||
debug!(
|
||||
"drawing with size: {}, {}",
|
||||
scaled_width, height_to_scale_to
|
||||
);
|
||||
|
@@ -3,8 +3,10 @@ mod draw;
|
||||
mod ui;
|
||||
|
||||
use clap::Parser;
|
||||
use env_logger::Env;
|
||||
use gtk::prelude::*;
|
||||
use gtk::Application;
|
||||
use log::debug;
|
||||
use std::cell::RefCell;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
@@ -19,8 +21,9 @@ struct Cli {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("debug")).init();
|
||||
let cli = Cli::parse();
|
||||
println!("Parse args");
|
||||
debug!("Parse args");
|
||||
let app = Application::builder().application_id(APP_ID).build();
|
||||
|
||||
app.connect_activate(move |app| {
|
||||
|
11
src/ui.rs
11
src/ui.rs
@@ -9,6 +9,7 @@ use gtk::{
|
||||
glib, Application, ApplicationWindow, Box, Button, FileChooserAction, FileChooserDialog,
|
||||
HeaderBar, Label, Orientation, Picture, ResponseType,
|
||||
};
|
||||
use log::debug;
|
||||
|
||||
use crate::cache::{self, CacheCommand};
|
||||
use glib::clone;
|
||||
@@ -62,7 +63,7 @@ impl DocumentCanvas {
|
||||
}
|
||||
|
||||
pub fn cache_surrounding_pages(&self, area_height: i32) {
|
||||
println!("Send cache request");
|
||||
debug!("Send cache request");
|
||||
self.page_cache_sender
|
||||
.send_blocking(CacheCommand::CachePages {
|
||||
pages: vec![
|
||||
@@ -164,7 +165,7 @@ fn process_left_click(ui: &mut Ui, x: f64, y: f64) {
|
||||
|
||||
impl Ui {
|
||||
pub fn build(app: &Application) -> Rc<RefCell<Ui>> {
|
||||
println!("building ui");
|
||||
debug!("building ui");
|
||||
let open_file_button = Button::from_icon_name("document-open");
|
||||
|
||||
let app_wrapper = Box::builder().orientation(Orientation::Vertical).build();
|
||||
@@ -268,7 +269,7 @@ fn choose_file(ui: Rc<RefCell<Ui>>, window: &ApplicationWindow) {
|
||||
}
|
||||
|
||||
pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
println!("Loading file...");
|
||||
debug!("Loading file...");
|
||||
// TODO: catch errors, maybe show error dialog
|
||||
let path: PathBuf = file.as_ref().to_path_buf();
|
||||
let uri = format!("file://{}", path.to_str().unwrap());
|
||||
@@ -293,7 +294,7 @@ pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
ui.borrow_mut().image_right.set_visible(true);
|
||||
let area_height = ui.borrow().image_left.height();
|
||||
ui.borrow().document_canvas.as_ref().unwrap().cache_surrounding_pages(area_height);
|
||||
println!("Image size: {}, {}", ui.borrow().image_left.width(), ui.borrow().image_left.height());
|
||||
debug!("Image size: {}, {}", ui.borrow().image_left.width(), ui.borrow().image_left.height());
|
||||
}
|
||||
}),
|
||||
);
|
||||
@@ -305,5 +306,5 @@ pub fn load_document(file: impl AsRef<Path>, ui: Rc<RefCell<Ui>>) {
|
||||
ui.borrow_mut().document_canvas = Some(document_canvas);
|
||||
|
||||
update_page_status(&ui.borrow());
|
||||
println!("finished loading document");
|
||||
debug!("finished loading document");
|
||||
}
|
||||
|
Reference in New Issue
Block a user