This commit is contained in:
Julian Ospald 2017-07-05 21:51:46 +02:00
parent 00ffe55ecd
commit 973e6a0257
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
3 changed files with 43 additions and 21 deletions

View File

@ -22,6 +22,7 @@ toml = "^0.4.2"
serde_derive = "^1.0.9" serde_derive = "^1.0.9"
serde = "^1.0.9" serde = "^1.0.9"
xdg = "*" xdg = "*"
which = "*"
[dependencies.gtk] [dependencies.gtk]
git = "https://github.com/gtk-rs/gtk.git" git = "https://github.com/gtk-rs/gtk.git"

View File

@ -26,6 +26,7 @@ extern crate gobject_sys;
extern crate gtk; extern crate gtk;
extern crate gtk_sys; extern crate gtk_sys;
extern crate libc; extern crate libc;
extern crate which;
extern crate xdg; extern crate xdg;
use std::rc::Rc; use std::rc::Rc;
@ -65,10 +66,10 @@ fn main() {
let apps = Rc::new(AppS::new()); let apps = Rc::new(AppS::new());
let mut prefs = prefs::Prefs::new().unwrap(); let mut prefs = prefs::Prefs::new().unwrap();
println!("Channel: {:?}", prefs.to_str()); println!("Channel: {}", prefs.to_str());
prefs.store_config(); prefs.store_config();
// println!("Channel: {:?}", prefs.to_str()); println!("Control_cmd: {:?}", prefs.get_avail_vol_control_cmd());
ui_entry::init(apps); ui_entry::init(apps);

View File

@ -1,8 +1,12 @@
use errors::*; use errors::*;
use toml; use std::fmt::Display;
use xdg; use std::fmt::Formatter;
use std::fs::File; use std::fs::File;
use std::io::prelude::*; use std::io::prelude::*;
use std;
use toml;
use which;
use xdg;
@ -28,17 +32,6 @@ impl Default for MiddleClickAction {
} }
#[derive(Deserialize, Debug, Serialize, Default)]
#[serde(default)]
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)] #[derive(Deserialize, Debug, Serialize)]
#[serde(default)] #[serde(default)]
pub struct DevicePrefs { pub struct DevicePrefs {
@ -101,7 +94,7 @@ impl Default for VolColor {
#[derive(Deserialize, Debug, Serialize)] #[derive(Deserialize, Debug, Serialize)]
#[serde(default)] #[serde(default)]
pub struct BehaviorPrefs { pub struct BehaviorPrefs {
vol_control_cmd: Option<String>, pub vol_control_cmd: Option<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?
@ -142,8 +135,15 @@ impl Default for NotifyPrefs {
} }
#[derive(Deserialize, Debug, Serialize, Default)]
#[serde(default)]
pub struct Prefs {
pub device_prefs: DevicePrefs,
pub view_prefs: ViewPrefs,
pub behavior_prefs: BehaviorPrefs,
pub notify_prefs: NotifyPrefs,
// TODO: HotKeys?
}
impl Prefs { impl Prefs {
pub fn new() -> Result<Prefs> { pub fn new() -> Result<Prefs> {
@ -201,12 +201,32 @@ impl Prefs {
} }
// TODO: implement pub fn get_avail_vol_control_cmd(&self) -> Option<String> {
pub fn vol_control_cmd() -> String { match self.behavior_prefs.vol_control_cmd {
return String::from(""); Some(ref c) => return Some(c.clone()),
None => {
for command in VOL_CONTROL_COMMANDS.iter() {
if which::which(command).is_ok() {
return Some(String::from(*command));
}
}
}
}
return None;
} }
} }
impl Display for Prefs {
fn fmt(&self,
f: &mut Formatter)
-> std::result::Result<(), std::fmt::Error> {
let s = self.to_str();
return write!(f, "{}", s);
}
}
fn get_xdg_dirs() -> xdg::BaseDirectories { fn get_xdg_dirs() -> xdg::BaseDirectories {
return xdg::BaseDirectories::with_prefix("pnmixer-rs").unwrap(); return xdg::BaseDirectories::with_prefix("pnmixer-rs").unwrap();
} }