diff --git a/Cargo.lock b/Cargo.lock index eb915a0..13dba39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "configparser" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288" + [[package]] name = "memchr" version = "2.7.1" @@ -21,6 +27,7 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" name = "mycelium" version = "0.1.0" dependencies = [ + "configparser", "untildify", ] diff --git a/Cargo.toml b/Cargo.toml index aa60f22..ecaca2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] +configparser = "3.0.4" untildify = "0.1.1" diff --git a/src/config.rs b/src/config.rs index be15968..5bc2a89 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,8 @@ +use configparser::ini::Ini; use core::fmt; use std::fs::File; use std::io::prelude::*; + use untildify; #[derive(Debug)] @@ -8,6 +10,18 @@ pub enum WallpaperHandler { Feh, Plasma, Gnome, + Error, +} + +impl WallpaperHandler { + pub fn new(handler: String) -> WallpaperHandler { + match handler.as_str() { + "feh" => WallpaperHandler::Feh, + "plasma" => WallpaperHandler::Plasma, + "gnome" => WallpaperHandler::Gnome, + _ => WallpaperHandler::Error, + } + } } impl fmt::Display for WallpaperHandler { @@ -108,10 +122,32 @@ impl fmt::Display for Config { } impl Config { - pub fn load_from_file(self, file_path: String) -> String { - let mut file = File::open(file_path).unwrap(); - let mut contents = String::new(); - file.read_to_string(&mut contents).unwrap(); - contents + pub fn parse_config(self, file_path: String) -> Config { + let mut config = Ini::new(); + let map = config.load(file_path).unwrap(); + // let file_contents = Config::load_from_file(file_path); + + // Get the wallpaper engine and parse it + let wallpaper_engine = + WallpaperHandler::new(config.get("general", "wallpaper_engine").unwrap()); + // + + // Get the wallpaper dirs and parse them + + // + + // Get the Monitors and parse them + for mon in map.get("monitors") { + println!("{:?}", mon); + } + println!("{:?}", map.get("monitors")); + // + + Config { + x_server: config.get("general", "x_server").unwrap(), + wallpaper_engine: wallpaper_engine, + wallpaper_dir: WallpaperDir::new(), + monitors: Monitors::new(), + } } } diff --git a/src/main.rs b/src/main.rs index c1db1e9..c2eae3f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,9 @@ mod config; fn main() { let config = config::Config::new(); - + // config.parse_config("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned()) println!( "{}", - config.load_from_file("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned()) + config.parse_config("/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned()) ); }