use simplelog to log messages
Signed-off-by: Fabrizio Iannetti <fabrizio.iannetti@gmail.com>
This commit is contained in:
parent
e7a2ee9d80
commit
ae9abb7768
File diff suppressed because it is too large
Load Diff
|
@ -15,6 +15,8 @@ lttng-ust = { version = "0.1.0", optional = true }
|
|||
icalendar = "0.15.4"
|
||||
directories = "5.0.1"
|
||||
clap = { version = "4.3.11", features = ["derive"] }
|
||||
log = { version = "0.4", features = ["std", "serde"] }
|
||||
simplelog = { version = "^0.12.0", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
#lttng-ust-generate = "0.1.0"
|
||||
|
|
58
src/main.rs
58
src/main.rs
|
@ -3,31 +3,36 @@ mod ui;
|
|||
mod model;
|
||||
|
||||
use ui::calendar;
|
||||
use model::events::EventsCollection;
|
||||
use model::ical_bridge::load_calendar;
|
||||
|
||||
use model::{
|
||||
events::EventsCollection,
|
||||
ical_bridge::load_calendar,
|
||||
};
|
||||
use chrono::{Datelike, NaiveDate, Months, Utc};
|
||||
use calendar::{CalendarParams, CalendarView };
|
||||
use calendar::CalendarViewMode as ViewMode;
|
||||
|
||||
use std::path;
|
||||
use clap;
|
||||
use clap::Parser;
|
||||
|
||||
use log::info;
|
||||
use simplelog::{SimpleLogger, Config};
|
||||
use iced::{
|
||||
alignment,
|
||||
executor,
|
||||
Alignment, Application, Command,
|
||||
Element, Length, Settings,
|
||||
Alignment,
|
||||
Application,
|
||||
Command,
|
||||
Element,
|
||||
Length,
|
||||
Settings,
|
||||
widget::{
|
||||
Column,
|
||||
Row,
|
||||
Container,
|
||||
Button,
|
||||
Text,
|
||||
pick_list,
|
||||
},
|
||||
theme,
|
||||
};
|
||||
use iced::widget::{
|
||||
Column, Row,
|
||||
Container,
|
||||
Button, Text,
|
||||
pick_list,
|
||||
};
|
||||
//use iced::button;
|
||||
use iced::theme;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
extern crate lttng_ust;
|
||||
|
@ -52,12 +57,21 @@ struct CliArgs {
|
|||
}
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
set_up_logger();
|
||||
|
||||
let args = CliArgs::parse();
|
||||
let calendar_files = args.files.iter().map(|arg| path::PathBuf::from(arg)).collect();
|
||||
//let calendar_files = vec![path::PathBuf::from("/home/fab/calendario.ics")];
|
||||
let calendar_files = args.files.iter().map(|arg| {
|
||||
info!("CalFile: {}", arg);
|
||||
path::PathBuf::from(arg)
|
||||
}).collect();
|
||||
|
||||
CalendarApp::run(Settings::with_flags(CalendarFlags {calendar_paths: calendar_files}))
|
||||
}
|
||||
|
||||
fn set_up_logger() {
|
||||
SimpleLogger::init(log::LevelFilter::Info, Config::default()).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct CalendarApp {
|
||||
month: NaiveDate,
|
||||
|
@ -149,15 +163,19 @@ impl Controls {
|
|||
|
||||
fn get_msg_next(&self) -> Message {
|
||||
match self.mode {
|
||||
Some(ViewMode::Week) => Message::NextWeek,
|
||||
Some(ViewMode::Month) => Message::NextMonth,
|
||||
_ => Message::NextYear
|
||||
Some(ViewMode::Year) => Message::NextYear,
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_msg_prev(&self) -> Message {
|
||||
match self.mode {
|
||||
Some(ViewMode::Week) => Message::PrevWeek,
|
||||
Some(ViewMode::Month) => Message::PrevMonth,
|
||||
_ => Message::PrevYear
|
||||
Some(ViewMode::Year) => Message::PrevYear,
|
||||
None => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use icalendar::{Component, DatePerhapsTime, CalendarDateTime, CalendarComponent}
|
|||
use chrono::NaiveDate;
|
||||
use crate::EventsCollection;
|
||||
use std::fs;
|
||||
use log::warn;
|
||||
|
||||
fn cdt_as_date(cdt: &CalendarDateTime) -> NaiveDate {
|
||||
match cdt {
|
||||
|
@ -25,12 +26,16 @@ fn create_event(events: &mut EventsCollection, event: &icalendar::Event) {
|
|||
|
||||
pub fn load_calendar(calendar_path: &std::path::Path, events: &mut EventsCollection) {
|
||||
let mut calendar = icalendar::Calendar::new();
|
||||
let contents = fs::read_to_string(calendar_path)
|
||||
.expect("Could not read the calendar");
|
||||
|
||||
let contents = match fs::read_to_string(calendar_path) {
|
||||
Ok(file_content) => file_content,
|
||||
Err(e) => { warn!("Could not read the calendar: {}", e); return; },
|
||||
};
|
||||
|
||||
let res = icalendar::parser::read_calendar(&contents);
|
||||
match res {
|
||||
Ok(parsed_calendar) => { calendar.extend(parsed_calendar.components); }
|
||||
Err(e) => println!("{}", e)
|
||||
Ok(parsed_calendar) => { calendar.extend(parsed_calendar.components); },
|
||||
Err(e) => { warn!("Error parsing calendar {}", e); return; }
|
||||
}
|
||||
|
||||
for cc in calendar.iter() {
|
||||
|
|
Loading…
Reference in New Issue