Update
This commit is contained in:
parent
aa60ab2c9c
commit
0847a1087b
@ -18,6 +18,9 @@ ffi = "^0.0.2"
|
|||||||
flexi_logger = "^0.5.1"
|
flexi_logger = "^0.5.1"
|
||||||
log = "^0.3.8"
|
log = "^0.3.8"
|
||||||
error-chain = { path = "3rdparty/error-chain" }
|
error-chain = { path = "3rdparty/error-chain" }
|
||||||
|
toml = "^0.4.2"
|
||||||
|
serde_derive = "^1.0.9"
|
||||||
|
serde = "^1.0.9"
|
||||||
|
|
||||||
[dependencies.gtk]
|
[dependencies.gtk]
|
||||||
git = "https://github.com/gtk-rs/gtk.git"
|
git = "https://github.com/gtk-rs/gtk.git"
|
||||||
|
11
src/main.rs
11
src/main.rs
@ -8,6 +8,11 @@ extern crate log;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate error_chain;
|
extern crate error_chain;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
|
extern crate toml;
|
||||||
|
extern crate serde;
|
||||||
|
|
||||||
extern crate alsa;
|
extern crate alsa;
|
||||||
extern crate alsa_sys;
|
extern crate alsa_sys;
|
||||||
extern crate ffi;
|
extern crate ffi;
|
||||||
@ -43,6 +48,7 @@ mod support_ui;
|
|||||||
mod support_alsa;
|
mod support_alsa;
|
||||||
|
|
||||||
use app_state::*;
|
use app_state::*;
|
||||||
|
use prefs::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -57,6 +63,11 @@ fn main() {
|
|||||||
|
|
||||||
let apps = Rc::new(AppS::new());
|
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);
|
ui_entry::init(apps);
|
||||||
|
|
||||||
gtk::main();
|
gtk::main();
|
||||||
|
109
src/prefs.rs
109
src/prefs.rs
@ -1,26 +1,31 @@
|
|||||||
use errors::*;
|
use errors::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use glib;
|
use glib;
|
||||||
use glib::KeyFile;
|
use toml;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const DEFAULT_PREFS: &str = "[PNMixer]\n
|
const DEFAULT_PREFS: &str = "[device_prefs]
|
||||||
AlsaCard=(default)\n
|
card = \"default\"
|
||||||
AlsaChannel=Master\n
|
channel = \"Master\"
|
||||||
DrawVolMeter=True\n
|
|
||||||
VolMeterOffset=10\n
|
[view_prefs]
|
||||||
VolMeterColor=245;121;0;\n
|
draw_vol_meter = true
|
||||||
SystemTheme=true\n
|
vol_meter_offset = 10
|
||||||
VolControlCommand=xfce4-mixer\n
|
vol_meter_color = { red = 245, blue = 121, green = 0 }
|
||||||
VolControlStep=5\n
|
system_theme = true
|
||||||
MiddleClickAction=0\n
|
|
||||||
CustomCommand=\n
|
[behavior_prefs]
|
||||||
EnableNotifications=true\n
|
vol_control_cmd = \"\"
|
||||||
NotificationTimeout=1500\n
|
vol_scroll_step = 5.0
|
||||||
MouseNotifications=true\n
|
middle_click_action = \"ToggleMute\"
|
||||||
PopupNotifcations=true\n
|
|
||||||
ExternalNotifications=true\n";
|
[notify_prefs]
|
||||||
|
enable_notifications = true
|
||||||
|
notifcation_timeout = 1500
|
||||||
|
notify_mouse_scroll = true
|
||||||
|
notify_popup = true
|
||||||
|
notify_external = true";
|
||||||
|
|
||||||
|
|
||||||
const VOL_CONTROL_COMMANDS: [&str; 3] = [
|
const VOL_CONTROL_COMMANDS: [&str; 3] = [
|
||||||
@ -31,6 +36,7 @@ const VOL_CONTROL_COMMANDS: [&str; 3] = [
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
pub enum MiddleClickAction {
|
pub enum MiddleClickAction {
|
||||||
ToggleMute,
|
ToggleMute,
|
||||||
ShowPreferences,
|
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 card: String,
|
||||||
pub channel: String,
|
pub channel: String,
|
||||||
// TODO: normalize volume?
|
// TODO: normalize volume?
|
||||||
|
}
|
||||||
|
|
||||||
/* view prefs */
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
|
pub struct ViewPrefs {
|
||||||
pub draw_vol_meter: bool,
|
pub draw_vol_meter: bool,
|
||||||
pub vol_meter_offset: i64,
|
pub vol_meter_offset: i64,
|
||||||
pub vol_meter_color: (u8, u8, u8),
|
pub vol_meter_color: VolColor,
|
||||||
pub system_theme: bool,
|
pub system_theme: bool,
|
||||||
// TODO: Display text folume/text volume pos?
|
// 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_control_cmd: String,
|
||||||
pub vol_scroll_step: f64,
|
pub vol_scroll_step: f64,
|
||||||
pub middle_click_action: MiddleClickAction,
|
pub middle_click_action: MiddleClickAction,
|
||||||
// TODO: fine scroll step?
|
// TODO: fine scroll step?
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: HotKeys?
|
#[derive(Deserialize, Debug, Serialize)]
|
||||||
|
pub struct NotifyPrefs {
|
||||||
/* notifications */
|
|
||||||
pub enable_notifications: bool,
|
pub enable_notifications: bool,
|
||||||
pub notifcation_timeout: i64,
|
pub notifcation_timeout: i64,
|
||||||
pub notify_mouse_scroll: bool,
|
pub notify_mouse_scroll: bool,
|
||||||
@ -73,28 +98,42 @@ struct Prefs {
|
|||||||
|
|
||||||
|
|
||||||
impl Prefs {
|
impl Prefs {
|
||||||
pub fn new() -> Prefs {
|
// pub fn set_blah(&mut self) {
|
||||||
// load from config
|
// 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() {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user