From 0847a1087bb4d226a590dc39e85115da07b7cc75 Mon Sep 17 00:00:00 2001 From: "Ospald, Julian" Date: Wed, 5 Jul 2017 17:14:55 +0200 Subject: [PATCH] Update --- Cargo.toml | 3 ++ src/main.rs | 11 ++++++ src/prefs.rs | 109 ++++++++++++++++++++++++++++++++++----------------- 3 files changed, 88 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 240203028..78a85a3ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,9 @@ ffi = "^0.0.2" flexi_logger = "^0.5.1" log = "^0.3.8" error-chain = { path = "3rdparty/error-chain" } +toml = "^0.4.2" +serde_derive = "^1.0.9" +serde = "^1.0.9" [dependencies.gtk] git = "https://github.com/gtk-rs/gtk.git" diff --git a/src/main.rs b/src/main.rs index 98a5b7ed0..4bb52ef01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,11 @@ extern crate log; #[macro_use] extern crate error_chain; +#[macro_use] +extern crate serde_derive; +extern crate toml; +extern crate serde; + extern crate alsa; extern crate alsa_sys; extern crate ffi; @@ -43,6 +48,7 @@ mod support_ui; mod support_alsa; use app_state::*; +use prefs::*; @@ -57,6 +63,11 @@ fn main() { let apps = Rc::new(AppS::new()); + let mut prefs = prefs::Prefs::new_from_def(); + prefs.behavior_prefs.middle_click_action = MiddleClickAction::CustomCommand(String::from("Gaga")); + println!("Channel: {:?}", prefs.to_str()); + + ui_entry::init(apps); gtk::main(); diff --git a/src/prefs.rs b/src/prefs.rs index 3fc81d9d2..31f4d6e93 100644 --- a/src/prefs.rs +++ b/src/prefs.rs @@ -1,26 +1,31 @@ use errors::*; use std::path::Path; use glib; -use glib::KeyFile; +use toml; -const DEFAULT_PREFS: &str = "[PNMixer]\n -AlsaCard=(default)\n -AlsaChannel=Master\n -DrawVolMeter=True\n -VolMeterOffset=10\n -VolMeterColor=245;121;0;\n -SystemTheme=true\n -VolControlCommand=xfce4-mixer\n -VolControlStep=5\n -MiddleClickAction=0\n -CustomCommand=\n -EnableNotifications=true\n -NotificationTimeout=1500\n -MouseNotifications=true\n -PopupNotifcations=true\n -ExternalNotifications=true\n"; +const DEFAULT_PREFS: &str = "[device_prefs] +card = \"default\" +channel = \"Master\" + +[view_prefs] +draw_vol_meter = true +vol_meter_offset = 10 +vol_meter_color = { red = 245, blue = 121, green = 0 } +system_theme = true + +[behavior_prefs] +vol_control_cmd = \"\" +vol_scroll_step = 5.0 +middle_click_action = \"ToggleMute\" + +[notify_prefs] +enable_notifications = true +notifcation_timeout = 1500 +notify_mouse_scroll = true +notify_popup = true +notify_external = true"; const VOL_CONTROL_COMMANDS: [&str; 3] = [ @@ -31,6 +36,7 @@ const VOL_CONTROL_COMMANDS: [&str; 3] = [ +#[derive(Deserialize, Debug, Serialize)] pub enum MiddleClickAction { ToggleMute, ShowPreferences, @@ -39,30 +45,49 @@ pub enum MiddleClickAction { } -struct Prefs { - key_file: glib::KeyFile, - /* device prefs */ +#[derive(Deserialize, Debug, Serialize)] +pub struct Prefs { + pub device_prefs: DevicePrefs, + pub view_prefs: ViewPrefs, + pub behavior_prefs: BehaviorPrefs, + pub notify_prefs: NotifyPrefs, + // TODO: HotKeys? +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct DevicePrefs { pub card: String, pub channel: String, // TODO: normalize volume? +} - /* view prefs */ +#[derive(Deserialize, Debug, Serialize)] +pub struct ViewPrefs { pub draw_vol_meter: bool, pub vol_meter_offset: i64, - pub vol_meter_color: (u8, u8, u8), + pub vol_meter_color: VolColor, pub system_theme: bool, // TODO: Display text folume/text volume pos? +} - /* behavior */ +#[derive(Deserialize, Debug, Serialize)] +pub struct VolColor { + pub red: u8, + pub green: u8, + pub blue: u8, +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct BehaviorPrefs { pub vol_control_cmd: String, pub vol_scroll_step: f64, pub middle_click_action: MiddleClickAction, // TODO: fine scroll step? +} - // TODO: HotKeys? - - /* notifications */ +#[derive(Deserialize, Debug, Serialize)] +pub struct NotifyPrefs { pub enable_notifications: bool, pub notifcation_timeout: i64, pub notify_mouse_scroll: bool, @@ -73,28 +98,42 @@ struct Prefs { impl Prefs { - pub fn new() -> Prefs { - // load from config + // pub fn set_blah(&mut self) { + // self.vol_scroll_step = 5.0; + // } - } + // pub fn new() -> Prefs { + // // load from config - pub fn reload_from_config(&self) { + // } - } + // pub fn reload_from_config(&self) { + + // } - pub fn save_to_config() -> Result<()> { + // pub fn save_to_config() -> Result<()> { - } + // } - fn config_path() -> String { + // fn config_path() -> String { - } + // } fn ensure_config_path() { } + + pub fn new_from_def() -> Prefs { + let prefs: Prefs = toml::from_str(DEFAULT_PREFS).unwrap(); + return prefs; + } + + + pub fn to_str(&self) -> String { + return toml::to_string(self).unwrap(); + } }