diff --git a/Linux/Cargo.lock b/Linux/Cargo.lock index 0b94ab8..91f63fc 100644 --- a/Linux/Cargo.lock +++ b/Linux/Cargo.lock @@ -9,9 +9,11 @@ dependencies = [ "env_logger", "log", "min-rs", + "platform-dirs", "relm4", "relm4-icons", "rust-i18n", + "serde", "slint-build", "walkdir", ] @@ -358,6 +360,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "dirs-next" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "displaydoc" version = "0.2.4" @@ -1297,6 +1320,16 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.5.0", + "libc", +] + [[package]] name = "linked-hash-map" version = "0.5.6" @@ -1535,6 +1568,15 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" +[[package]] +name = "platform-dirs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e188d043c1a692985f78b5464853a263f1a27e5bd6322bad3a4078ee3c998a38" +dependencies = [ + "dirs-next", +] + [[package]] name = "png" version = "0.17.13" @@ -1624,6 +1666,17 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redox_users" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + [[package]] name = "regex" version = "1.10.5" @@ -2514,6 +2567,22 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + [[package]] name = "winapi-util" version = "0.1.8" @@ -2523,6 +2592,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Linux/Cargo.toml b/Linux/Cargo.toml index 3c58acf..aedb7aa 100644 --- a/Linux/Cargo.toml +++ b/Linux/Cargo.toml @@ -7,9 +7,11 @@ build = "build.rs" [dependencies] env_logger = "0.11.3" log = "0.4.21" +platform-dirs = "0.3.0" relm4 = "0.8.1" relm4-icons = "0.8.3" rust-i18n = "3.0.1" +serde = "1.0.203" [dependencies.min-rs] git = "https://github.com/MvRens/min-rs.git" diff --git a/Linux/locales/mainwindow.yml b/Linux/locales/mainwindow.yml index 4694ceb..4ee5659 100644 --- a/Linux/locales/mainwindow.yml +++ b/Linux/locales/mainwindow.yml @@ -3,3 +3,14 @@ _version: 2 mainwindow: title: en: MassiveKnob + tab: + device: + en: Device + analoginputs: + en: Analog inputs + digitalinputs: + en: Digital inputs + analogoutputs: + en: Analog outputs + digitaloutputs: + en: Digital outputs \ No newline at end of file diff --git a/Linux/src/config.rs b/Linux/src/config.rs new file mode 100644 index 0000000..f314c2b --- /dev/null +++ b/Linux/src/config.rs @@ -0,0 +1,55 @@ +use std::path::{Path, PathBuf}; +use std::io::{Error, Read, Write}; +use platform_dirs::AppDirs; + + +pub struct Config +{ + root: PathBuf +} + + +impl Config +{ + pub fn new() -> Self + { + let appdirs = AppDirs::new(Some("massiveknob"), false).unwrap(); + + Self + { + root: appdirs.data_dir + } + } + + + pub fn get_reader(&self, name: &str) -> Option + { + let path = Path::join(&self.root, name); + if !path.exists() + { + return None; + } + + match std::fs::File::open(path) + { + Ok(v) => Some(v), + Err(_) => None + } + } + + + pub fn get_writer(&self, name: &str) -> Result + { + let path = Path::join(&self.root, name); + if !path.exists() + { + match std::fs::create_dir_all(path.clone()) + { + Ok(_v) => (), + Err(e) => return Err(e) + } + } + + std::fs::File::create(path) + } +} diff --git a/Linux/src/devices/emulator/mod.rs b/Linux/src/devices/emulator/mod.rs index 5d2ac7e..a051db6 100644 --- a/Linux/src/devices/emulator/mod.rs +++ b/Linux/src/devices/emulator/mod.rs @@ -1,6 +1,6 @@ -use emulatorwindow::EmulatorWindow; -use relm4::prelude::*; -use relm4::gtk::prelude::GtkApplicationExt; +//use emulatorwindow::EmulatorWindow; +//use relm4::prelude::*; +//use relm4::gtk::prelude::GtkApplicationExt; use super::registry::{MkDevice, register_device}; @@ -12,10 +12,12 @@ pub mod emulatorwindow; pub fn register() { register_device(MkDevice::new("Emulator")); +} +/* let app = relm4::main_application(); let builder = EmulatorWindow::builder(); app.add_window(&builder.root); builder.launch(()).detach_runtime(); -} \ No newline at end of file +*/ \ No newline at end of file diff --git a/Linux/src/main.rs b/Linux/src/main.rs index 1a6426b..60342ed 100644 --- a/Linux/src/main.rs +++ b/Linux/src/main.rs @@ -10,6 +10,7 @@ i18n!("locales"); pub mod devices; pub mod actions; +pub mod config; pub mod mainwindow; fn main() @@ -18,12 +19,20 @@ fn main() // .format_timestamp(None) .init(); - //devices::register(); + devices::register(); actions::register(); relm4_icons::initialize_icons(); - let app = RelmApp::new("com.github.mvrens.massiveknob"); + load_config(); + let app = RelmApp::new("com.github.mvrens.massiveknob"); app.run::(()); +} + + +fn load_config() +{ + //let config = config::Config::new(); + //config.get_reader(name) } \ No newline at end of file diff --git a/Linux/src/mainwindow.rs b/Linux/src/mainwindow.rs index 533c95f..47e6d9a 100644 --- a/Linux/src/mainwindow.rs +++ b/Linux/src/mainwindow.rs @@ -7,36 +7,51 @@ pub struct MainWindow #[derive(Debug)] -pub enum Msg +pub enum MainWindowMsg +{ +} + + +pub struct MainWindowWidgets { } -#[relm4::component(pub)] impl SimpleComponent for MainWindow { type Init = (); - type Input = Msg; + type Input = MainWindowMsg; type Output = (); + type Root = gtk::Window; + type Widgets = MainWindowWidgets; - view! - { - gtk::Window - { - set_title: Some(&t!("mainwindow.title")), - set_default_size: (300, 100) - } + + fn init_root() -> Self::Root + { + // I prefer not to use the view! macro, as VSCode / rust-analyzer will not provide autocompletion + gtk::Window::builder() + .title(t!("mainwindow.title")) + .default_width(500) + .default_height(500) + .build() } - fn init(_data: Self::Init, root: Self::Root, _sender: ComponentSender, ) -> ComponentParts + fn init(_data: Self::Init, window: Self::Root, _sender: ComponentSender, ) -> ComponentParts { - // TEMP - device should not use GTK at register time - crate::devices::register(); - let model = MainWindow {}; - let widgets = view_output!(); + let tabs = gtk::Notebook::builder().build(); + window.set_child(Some(&tabs)); + + add_box_tab(&tabs, "mainwindow.tab.device"); + add_box_tab(&tabs, "mainwindow.tab.analoginputs"); + add_box_tab(&tabs, "mainwindow.tab.digitalinputs"); + //add_box_tab(&tabs, "mainwindow.tab.analogoutputs"); + //add_box_tab(&tabs, "mainwindow.tab.digitaloutputs"); + + + let widgets = MainWindowWidgets {}; ComponentParts { model, widgets } } @@ -47,4 +62,20 @@ impl SimpleComponent for MainWindow { } } +} + + +fn add_box_tab(notebook: >k::Notebook, title_key: &str) -> gtk::Box +{ + let tab = gtk::Box::builder() + .orientation(gtk::Orientation::Vertical) + .build(); + + let tab_label = gtk::Label::builder() + .label(t!(title_key)) + .build(); + + notebook.append_page(&tab, Some(&tab_label)); + + tab } \ No newline at end of file