From bbe332f1076203357dfd5f2237f40ff48f7ab3f2 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sun, 2 Jul 2017 18:11:56 +0200 Subject: [PATCH] Update --- data/ui/prefs-dialog.glade | 207 +++++++++++++++---------------------- src/alsa_pn.rs | 46 ++++++++- src/app_state.rs | 36 ++++--- src/audio.rs | 182 ++++++++++++++++++++------------ src/errors.rs | 20 ++-- src/ui_entry.rs | 2 + src/ui_popup_menu.rs | 23 +++++ src/ui_prefs_dialog.rs | 119 +++++++++++++++++++++ 8 files changed, 420 insertions(+), 215 deletions(-) create mode 100644 src/ui_prefs_dialog.rs diff --git a/data/ui/prefs-dialog.glade b/data/ui/prefs-dialog.glade index 9e9a4dc61..f21882ce5 100644 --- a/data/ui/prefs-dialog.glade +++ b/data/ui/prefs-dialog.glade @@ -1,24 +1,11 @@ - + - - True - False - start - vertical - 5 - - - True - False - center - Notification support disabled at compile time. - - - - - + + 100 + 1 + 10 1000000000 @@ -30,11 +17,11 @@ False start vertical - 5 True False + 0 none @@ -88,6 +75,9 @@ GTK_EXPAND + + + @@ -111,13 +101,14 @@ True False + 0 none True False - vertical 12 + vertical 3 @@ -203,12 +194,29 @@ - - 100 - 1 - 10 + + True + False + start + vertical + + + True + False + center + Notification support disabled at compile time. + + + + + + False + True + 0 + + - + 100 1 10 @@ -220,10 +228,10 @@ False - dialog PNMixer Preferences False preferences-system + dialog True @@ -234,7 +242,6 @@ True False - 10 end @@ -320,6 +327,11 @@ + + True + True + 1 + @@ -339,47 +351,20 @@ False start vertical - 5 True False + 0 none True False 12 - 3 + 2 2 15 - - - True - False - start - Slider Orientation: - - - GTK_EXPAND - - - - - True - False - 0 - - Vertical - Horizontal - - - - 1 - 2 - GTK_EXPAND - - Display Text Volume @@ -393,8 +378,6 @@ 2 - 1 - 2 GTK_EXPAND @@ -402,12 +385,12 @@ True False - Text Volume Position: start + Text Volume Position: - 2 - 3 + 1 + 2 GTK_EXPAND @@ -417,17 +400,17 @@ False 0 - Top - Bottom - Left - Right + Top + Bottom + Left + Right 1 2 - 2 - 3 + 1 + 2 GTK_EXPAND @@ -454,6 +437,7 @@ True False + 0 none @@ -483,8 +467,8 @@ True False - Volume Meter Offset (%): start + Volume Meter Offset (%): 1 @@ -496,8 +480,8 @@ True False - Volume Meter Color: start + Volume Meter Color: 2 @@ -563,6 +547,7 @@ True False + 0 none @@ -571,8 +556,8 @@ True True False - 12 start + 12 True @@ -611,26 +596,26 @@ False start vertical - 5 True False + 0 none True False 12 - 3 + 2 2 15 True False - Card: start + Card: GTK_EXPAND @@ -640,8 +625,8 @@ True False - Channel: start + Channel: 1 @@ -674,37 +659,6 @@ GTK_EXPAND - - - True - True - False - True - - - - - - 1 - 2 - 2 - 3 - GTK_EXPAND - - - - - True - False - Normalize Volume: - start - Change volume on a logarithmic scale, closer to human perception. - - - 2 - 3 - - @@ -721,6 +675,7 @@ False False 5 + 0 @@ -745,11 +700,11 @@ False start vertical - 5 True False + 0 none @@ -782,6 +737,7 @@ True False + 0 none @@ -796,8 +752,8 @@ True False - Scroll Step: start + Scroll Step: GTK_EXPAND @@ -807,8 +763,8 @@ True False - Fine Scroll Step: start + Fine Scroll Step: 1 @@ -820,12 +776,12 @@ True True - 2 - True False False scroll_step_adjustment + 2 + True 1 @@ -837,12 +793,12 @@ True True - 2 - True False False fine_scroll_step_adjustment + 2 + True 1 @@ -875,6 +831,7 @@ True False + 0 none @@ -889,8 +846,8 @@ True False - Middle Click Action: start + Middle Click Action: GTK_EXPAND @@ -900,8 +857,8 @@ True False - Custom Command: start + Custom Command: 1 @@ -914,10 +871,10 @@ True False - Mute/Unmute - Show Preferences - Volume Control - Custom (set below) + Mute/Unmute + Show Preferences + Volume Control + Custom (set below) @@ -984,18 +941,18 @@ False start vertical - 5 True False + 0 none True False - vertical 12 + vertical Enable HotKeys @@ -1026,8 +983,8 @@ True False - Command start + Command @@ -1037,8 +994,8 @@ True False - Mute/Unmute: start + Mute/Unmute: 1 @@ -1049,8 +1006,8 @@ True False - Volume Up: start + Volume Up: 2 @@ -1061,8 +1018,8 @@ True False - Volume Down: start + Volume Down: 3 @@ -1218,8 +1175,8 @@ - ok_button cancel_button + ok_button diff --git a/src/alsa_pn.rs b/src/alsa_pn.rs index f3a883090..873aaaee3 100644 --- a/src/alsa_pn.rs +++ b/src/alsa_pn.rs @@ -78,10 +78,21 @@ impl AlsaCard { } + pub fn card_name(&self) -> Result { + return self.card.get_name().from_err(); + } + + + pub fn chan_name(&self) -> Result { + let n = self.selem_id + .get_name() + .map(|y| String::from(y))?; + return Ok(n); + } + + pub fn selem(&self) -> Selem { - return get_selems(&self.mixer) - .nth(self.selem_id.get_index() as usize) - .unwrap(); + return self.mixer.find_selem(&self.selem_id).unwrap(); } @@ -254,6 +265,19 @@ pub fn get_alsa_cards() -> alsa::card::Iter { } +pub fn get_alsa_card_names() -> Vec { + let mut vec = vec![]; + for card in get_alsa_cards() { + match card.and_then(|c| c.get_name()) { + Ok(name) => vec.push(name), + _ => (), + } + } + + return vec; +} + + pub fn get_alsa_card_by_name(name: String) -> Result { for r_card in get_alsa_cards() { let card = r_card?; @@ -284,6 +308,22 @@ pub fn get_selems(mixer: &Mixer) -> Map Selem> { } +pub fn get_selem_names(mixer: &Mixer) -> Vec { + let mut vec = vec![]; + for selem in get_selems(mixer) { + let n = selem.get_id() + .get_name() + .map(|y| String::from(y)); + match n { + Ok(name) => vec.push(name), + _ => (), + } + } + + return vec; +} + + pub fn get_selem_by_name(mixer: &Mixer, name: String) -> Result { for selem in get_selems(mixer) { let n = selem.get_id() diff --git a/src/app_state.rs b/src/app_state.rs index 16fa47f9d..189358dae 100644 --- a/src/app_state.rs +++ b/src/app_state.rs @@ -1,8 +1,6 @@ use gtk; use audio::Audio; -use std::cell::RefCell; -use std::rc::Rc; -use glade_helpers::*; + // TODO: destructors @@ -19,8 +17,12 @@ impl AppS { let builder_popup_window = gtk::Builder::new_from_string(include_str!("../data/ui/popup-window.glade")); let builder_popup_menu = gtk::Builder::new_from_string(include_str!("../data/ui/popup-menu.glade")); + let builder_prefs_dialog = + gtk::Builder::new_from_string(include_str!("../data/ui/prefs-dialog.glade")); return AppS { - gui: Gui::new(builder_popup_window, builder_popup_menu), + gui: Gui::new(builder_popup_window, + builder_popup_menu, + builder_prefs_dialog), audio: Audio::new(None, Some(String::from("Master"))) .unwrap(), }; @@ -32,31 +34,41 @@ pub struct Gui { pub status_icon: gtk::StatusIcon, pub popup_window: PopupWindow, pub popup_menu: PopupMenu, + pub prefs_dialog: PrefsDialog, } impl Gui { pub fn new(builder_popup_window: gtk::Builder, - builder_popup_menu: gtk::Builder) + builder_popup_menu: gtk::Builder, + builder_prefs_dialog: gtk::Builder) -> Gui { return Gui { status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"), popup_window: PopupWindow::new(builder_popup_window), popup_menu: PopupMenu::new(builder_popup_menu), + prefs_dialog: PrefsDialog::new(builder_prefs_dialog), }; } } -create_builder_item!(PopupMenu, - menu_window: gtk::Window, - menubar: gtk::MenuBar, - menu: gtk::Menu, - about_item: gtk::MenuItem); - - create_builder_item!(PopupWindow, popup_window: gtk::Window, vol_scale_adj: gtk::Adjustment, vol_scale: gtk::Scale, mute_check: gtk::CheckButton); + + +create_builder_item!(PopupMenu, + menu_window: gtk::Window, + menubar: gtk::MenuBar, + menu: gtk::Menu, + about_item: gtk::MenuItem, + prefs_item: gtk::MenuItem); + + +create_builder_item!(PrefsDialog, + prefs_dialog: gtk::Dialog, + card_combo: gtk::ComboBoxText, + chan_combo: gtk::ComboBoxText); diff --git a/src/audio.rs b/src/audio.rs index 636af079a..a74a760fe 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -1,6 +1,7 @@ use errors::*; use glib; use std::cell::Cell; +use std::cell::Ref; use std::cell::RefCell; use std::rc::Rc; use std::f64; @@ -28,11 +29,34 @@ pub enum AudioSignal { } +#[derive(Clone)] +pub struct Handlers { + inner: Rc>>>, +} + + +impl Handlers { + fn new() -> Handlers { + return Handlers { inner: Rc::new(RefCell::new(vec![])) }; + } + + + fn borrow(&self) -> Ref>> { + return self.inner.borrow(); + } + + + fn add_handler(&self, cb: Box) { + self.inner.borrow_mut().push(cb); + } +} + + pub struct Audio { _cannot_construct: (), pub acard: RefCell>, pub last_action_timestamp: Rc>, - pub handlers: Rc>>>, + pub handlers: Handlers, pub scroll_step: Cell, } @@ -42,16 +66,18 @@ impl Audio { elem_name: Option) -> Result