Started globbing stuff
This commit is contained in:
parent
ed148b05cb
commit
3fc1f271d0
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -17,6 +17,12 @@ version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.1"
|
||||
@ -28,6 +34,7 @@ name = "mycelium"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"configparser",
|
||||
"glob",
|
||||
"untildify",
|
||||
]
|
||||
|
||||
@ -63,8 +70,6 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
|
||||
[[package]]
|
||||
name = "untildify"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "992d9e1100cf171942054a07eef9a04986cc8acdb1f771be47accaa301a46bb7"
|
||||
dependencies = [
|
||||
"regex",
|
||||
]
|
||||
|
||||
@ -5,4 +5,5 @@ edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
configparser = "3.0.4"
|
||||
untildify = "0.1.1"
|
||||
glob = "0.3.1"
|
||||
untildify = { path = "../untildify" }
|
||||
|
||||
@ -1,59 +1,9 @@
|
||||
use configparser::ini::Ini;
|
||||
use core::fmt;
|
||||
use std::env::VarError;
|
||||
|
||||
use crate::enums::*;
|
||||
use untildify;
|
||||
|
||||
#[derive(Debug)]
|
||||
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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MonitorType {
|
||||
Ultrawide,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl MonitorType {
|
||||
fn new(mon_type: String) -> MonitorType {
|
||||
match mon_type.as_str() {
|
||||
"ultrawide" => MonitorType::Ultrawide,
|
||||
"vertical" => MonitorType::Vertical,
|
||||
"horizontal" => MonitorType::Horizontal,
|
||||
_ => MonitorType::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MonitorType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Monitors {
|
||||
monitors: Vec<MonitorType>,
|
||||
@ -95,6 +45,15 @@ impl WallpaperDir {
|
||||
vertical: expanded_tilde.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get(&self, monitor_type: MonitorType) -> String {
|
||||
match monitor_type {
|
||||
MonitorType::Ultrawide => self.ultrawide.to_string(),
|
||||
MonitorType::Horizontal => self.horizontal.to_string(),
|
||||
MonitorType::Vertical => self.vertical.to_string(),
|
||||
MonitorType::Error => "error".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for WallpaperDir {
|
||||
@ -126,15 +85,7 @@ impl Config {
|
||||
monitors: Monitors::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Config {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Mycelium Config: X Server: {xserv}, Wallpaper Engine: {wallpaper_engine}, Wallpaper Directories: {wallpaper_dirs}, Monitors: {monitors}", xserv = self.x_server, wallpaper_engine = self.wallpaper_engine, wallpaper_dirs = self.wallpaper_dir, monitors = self.monitors)
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_config(file_path: String) -> Config {
|
||||
let mut config = Ini::new();
|
||||
let map = config.load(file_path).unwrap();
|
||||
@ -146,9 +97,12 @@ impl Config {
|
||||
|
||||
// Get the wallpaper dirs and parse them
|
||||
|
||||
let ultrawide_dir = config.get("general", "ultra_wall_dir").unwrap();
|
||||
let horizontal_dir = config.get("general", "hor_wall_dir").unwrap();
|
||||
let vert_wall_dir = config.get("general", "vert_wall_dir").unwrap();
|
||||
let ultrawide_dir =
|
||||
untildify::untildify(config.get("general", "ultra_wall_dir").unwrap().as_ref());
|
||||
let horizontal_dir =
|
||||
untildify::untildify(config.get("general", "hor_wall_dir").unwrap().as_ref());
|
||||
let vert_wall_dir =
|
||||
untildify::untildify(config.get("general", "vert_wall_dir").unwrap().as_ref());
|
||||
let wallpaper_dir = WallpaperDir {
|
||||
ultrawide: ultrawide_dir,
|
||||
horizontal: horizontal_dir,
|
||||
@ -172,9 +126,15 @@ impl Config {
|
||||
|
||||
Config {
|
||||
x_server: config.get("general", "x_server").unwrap(),
|
||||
wallpaper_engine: wallpaper_engine,
|
||||
wallpaper_dir: wallpaper_dir,
|
||||
monitors: monitors,
|
||||
wallpaper_engine,
|
||||
wallpaper_dir,
|
||||
monitors,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Config {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "Mycelium Config: X Server: {xserv}, Wallpaper Engine: {wallpaper_engine}, Wallpaper Directories: {wallpaper_dirs}, Monitors: {monitors}", xserv = self.x_server, wallpaper_engine = self.wallpaper_engine, wallpaper_dirs = self.wallpaper_dir, monitors = self.monitors)
|
||||
}
|
||||
}
|
||||
|
||||
64
src/enums.rs
Normal file
64
src/enums.rs
Normal file
@ -0,0 +1,64 @@
|
||||
use core::fmt;
|
||||
|
||||
#[derive(Debug)]
|
||||
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 {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum MonitorType {
|
||||
Ultrawide,
|
||||
Horizontal,
|
||||
Vertical,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl MonitorType {
|
||||
pub fn new(mon_type: String) -> MonitorType {
|
||||
match mon_type.as_str() {
|
||||
"ultrawide" => MonitorType::Ultrawide,
|
||||
"vertical" => MonitorType::Vertical,
|
||||
"horizontal" => MonitorType::Horizontal,
|
||||
_ => MonitorType::Error,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for MonitorType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ImageTypes {
|
||||
PNG,
|
||||
JPG,
|
||||
JPEG,
|
||||
}
|
||||
|
||||
impl fmt::Display for ImageTypes {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
85
src/files.rs
Normal file
85
src/files.rs
Normal file
@ -0,0 +1,85 @@
|
||||
use core::fmt;
|
||||
use glob::glob;
|
||||
use std::process::exit;
|
||||
|
||||
use crate::config::*;
|
||||
use crate::enums::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Wallpaper {
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl Wallpaper {
|
||||
pub fn new(path: String) -> Wallpaper {
|
||||
Wallpaper { path }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Wallpaper {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self.path)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Wallpapers {
|
||||
ultrawide: Vec<Wallpaper>,
|
||||
horizontal: Vec<Wallpaper>,
|
||||
vertical: Vec<Wallpaper>,
|
||||
pub config: Config,
|
||||
}
|
||||
|
||||
impl Wallpapers {
|
||||
pub fn new() -> Wallpapers {
|
||||
Wallpapers {
|
||||
ultrawide: vec![],
|
||||
horizontal: vec![],
|
||||
vertical: vec![],
|
||||
config: Config::from_config(
|
||||
"/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned(),
|
||||
),
|
||||
}
|
||||
}
|
||||
// Todo implement a random selector for a given key, like `wallpapers.random_selection(MonitorType::Ultrawide)`
|
||||
pub fn random_selection(monitor_type: MonitorType) {}
|
||||
// Todo implement a function to load all files of particular filetypes into the Vec<Wallpaper>
|
||||
pub fn load_images(&mut self, monitor_type: MonitorType) {
|
||||
let mut path = self
|
||||
.config
|
||||
.wallpaper_dir
|
||||
.get(monitor_type.clone())
|
||||
.to_owned();
|
||||
path.push_str("/**/*.png");
|
||||
|
||||
for entry in glob(&path).unwrap() {
|
||||
match entry {
|
||||
Ok(path) => {
|
||||
self.add(monitor_type.clone(), path.display().to_string());
|
||||
}
|
||||
Err(e) => {
|
||||
println!("{}", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn add(&mut self, monitor_type: MonitorType, filepath: String) {
|
||||
match monitor_type {
|
||||
MonitorType::Ultrawide => self.ultrawide.push(Wallpaper { path: filepath }),
|
||||
MonitorType::Horizontal => self.horizontal.push(Wallpaper { path: filepath }),
|
||||
MonitorType::Vertical => self.vertical.push(Wallpaper { path: filepath }),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Wallpapers {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
writeln!(f, "Wallpapers discovered")?;
|
||||
for v in &self.ultrawide {
|
||||
writeln!(f, "{:?}", v)?;
|
||||
}
|
||||
writeln!(f, "")
|
||||
}
|
||||
}
|
||||
14
src/main.rs
14
src/main.rs
@ -1,9 +1,13 @@
|
||||
mod config;
|
||||
use crate::config::*;
|
||||
mod enums;
|
||||
use crate::enums::*;
|
||||
mod files;
|
||||
use crate::files::*;
|
||||
|
||||
fn main() {
|
||||
// let mut config = config::Config::new();
|
||||
let config = crate::config::Config::from_config(
|
||||
"/home/ben/.config/wallpaperctl/wallpaperctl.ini".to_owned(),
|
||||
);
|
||||
println!("{}", config);
|
||||
let mut wallpapers = Wallpapers::new();
|
||||
|
||||
wallpapers.load_images(MonitorType::Ultrawide);
|
||||
println!("{}", wallpapers);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user