Update
This commit is contained in:
parent
bbe332f107
commit
cc0530471f
@ -311,9 +311,7 @@ pub fn get_selems(mixer: &Mixer) -> Map<alsa::mixer::Iter, fn(Elem) -> Selem> {
|
|||||||
pub fn get_selem_names(mixer: &Mixer) -> Vec<String> {
|
pub fn get_selem_names(mixer: &Mixer) -> Vec<String> {
|
||||||
let mut vec = vec![];
|
let mut vec = vec![];
|
||||||
for selem in get_selems(mixer) {
|
for selem in get_selems(mixer) {
|
||||||
let n = selem.get_id()
|
let n = selem.get_id().get_name().map(|y| String::from(y));
|
||||||
.get_name()
|
|
||||||
.map(|y| String::from(y));
|
|
||||||
match n {
|
match n {
|
||||||
Ok(name) => vec.push(name),
|
Ok(name) => vec.push(name),
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -17,12 +17,9 @@ impl AppS {
|
|||||||
let builder_popup_window =
|
let builder_popup_window =
|
||||||
gtk::Builder::new_from_string(include_str!("../data/ui/popup-window.glade"));
|
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_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 {
|
return AppS {
|
||||||
gui: Gui::new(builder_popup_window,
|
gui: Gui::new(builder_popup_window, builder_popup_menu),
|
||||||
builder_popup_menu,
|
|
||||||
builder_prefs_dialog),
|
|
||||||
audio: Audio::new(None, Some(String::from("Master")))
|
audio: Audio::new(None, Some(String::from("Master")))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
};
|
};
|
||||||
@ -34,20 +31,18 @@ pub struct Gui {
|
|||||||
pub status_icon: gtk::StatusIcon,
|
pub status_icon: gtk::StatusIcon,
|
||||||
pub popup_window: PopupWindow,
|
pub popup_window: PopupWindow,
|
||||||
pub popup_menu: PopupMenu,
|
pub popup_menu: PopupMenu,
|
||||||
pub prefs_dialog: PrefsDialog,
|
/* prefs_dialog is dynamically created and destroyed */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Gui {
|
impl Gui {
|
||||||
pub fn new(builder_popup_window: gtk::Builder,
|
pub fn new(builder_popup_window: gtk::Builder,
|
||||||
builder_popup_menu: gtk::Builder,
|
builder_popup_menu: gtk::Builder)
|
||||||
builder_prefs_dialog: gtk::Builder)
|
|
||||||
-> Gui {
|
-> Gui {
|
||||||
return Gui {
|
return Gui {
|
||||||
status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"),
|
status_icon: gtk::StatusIcon::new_from_icon_name("pnmixer"),
|
||||||
popup_window: PopupWindow::new(builder_popup_window),
|
popup_window: PopupWindow::new(builder_popup_window),
|
||||||
popup_menu: PopupMenu::new(builder_popup_menu),
|
popup_menu: PopupMenu::new(builder_popup_menu),
|
||||||
prefs_dialog: PrefsDialog::new(builder_prefs_dialog),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,9 +61,3 @@ create_builder_item!(PopupMenu,
|
|||||||
menu: gtk::Menu,
|
menu: gtk::Menu,
|
||||||
about_item: gtk::MenuItem,
|
about_item: gtk::MenuItem,
|
||||||
prefs_item: gtk::MenuItem);
|
prefs_item: gtk::MenuItem);
|
||||||
|
|
||||||
|
|
||||||
create_builder_item!(PrefsDialog,
|
|
||||||
prefs_dialog: gtk::Dialog,
|
|
||||||
card_combo: gtk::ComboBoxText,
|
|
||||||
chan_combo: gtk::ComboBoxText);
|
|
||||||
|
@ -26,5 +26,4 @@ pub fn init(appstate: Rc<AppS>) {
|
|||||||
init_tray_icon(appstate.clone());
|
init_tray_icon(appstate.clone());
|
||||||
init_popup_window(appstate.clone());
|
init_popup_window(appstate.clone());
|
||||||
init_popup_menu(appstate.clone());
|
init_popup_menu(appstate.clone());
|
||||||
init_prefs_dialog(appstate.clone());
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use app_state::*;
|
|||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use gtk;
|
use gtk;
|
||||||
|
use ui_prefs_dialog::*;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -24,13 +25,12 @@ pub fn init_popup_menu(appstate: Rc<AppS>) {
|
|||||||
|
|
||||||
/* about_item.connect_activate_link */
|
/* about_item.connect_activate_link */
|
||||||
{
|
{
|
||||||
let apps = appstate.clone();
|
|
||||||
let prefs_item = &appstate.clone()
|
let prefs_item = &appstate.clone()
|
||||||
.gui
|
.gui
|
||||||
.popup_menu
|
.popup_menu
|
||||||
.prefs_item;
|
.prefs_item;
|
||||||
prefs_item.connect_activate(move |_| {
|
prefs_item.connect_activate(move |_| {
|
||||||
on_prefs_item_activate(&apps);
|
on_prefs_item_activate(appstate.clone());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,12 +74,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA."));
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_prefs_item_activate(appstate: &AppS) {
|
fn on_prefs_item_activate(appstate: Rc<AppS>) {
|
||||||
/* TODO: only create if needed */
|
/* TODO: only create if needed */
|
||||||
let prefs_dialog = &appstate.gui.prefs_dialog.prefs_dialog;
|
show_prefs_dialog(appstate);
|
||||||
let popup_menu = &appstate.gui.popup_menu.menu_window;
|
|
||||||
|
|
||||||
prefs_dialog.set_transient_for(popup_menu);
|
|
||||||
prefs_dialog.run();
|
|
||||||
// prefs_dialog.destroy();
|
|
||||||
}
|
}
|
||||||
|
@ -5,37 +5,63 @@ use gtk;
|
|||||||
use alsa_pn;
|
use alsa_pn;
|
||||||
|
|
||||||
|
|
||||||
pub fn init_prefs_dialog(appstate: Rc<AppS>) {
|
create_builder_item!(PrefsDialog,
|
||||||
/* prefs_dialog.connect_show */
|
prefs_dialog: gtk::Dialog,
|
||||||
{
|
card_combo: gtk::ComboBoxText,
|
||||||
let apps = appstate.clone();
|
chan_combo: gtk::ComboBoxText);
|
||||||
let prefs_dialog = &appstate.clone()
|
|
||||||
.gui
|
|
||||||
.prefs_dialog
|
|
||||||
.prefs_dialog;
|
|
||||||
prefs_dialog.connect_show(move |_| { on_prefs_dialog_show(&apps); });
|
|
||||||
}
|
|
||||||
|
|
||||||
/* card_combo.connect_changed */
|
|
||||||
{
|
|
||||||
let apps = appstate.clone();
|
|
||||||
let card_combo = &appstate.gui.prefs_dialog.card_combo;
|
|
||||||
|
|
||||||
card_combo.connect_changed(move |_| { on_card_combo_changed(&apps); });
|
|
||||||
}
|
|
||||||
/* card_combo.connect_changed */
|
|
||||||
{
|
|
||||||
let apps = appstate.clone();
|
|
||||||
let chan_combo = &appstate.gui.prefs_dialog.chan_combo;
|
|
||||||
|
|
||||||
chan_combo.connect_changed(move |_| { on_chan_combo_changed(&apps); });
|
|
||||||
|
pub fn show_prefs_dialog(appstate: Rc<AppS>) {
|
||||||
|
let builder_prefs_dialog = gtk::Builder::new_from_string(include_str!("../data/ui/prefs-dialog.glade"));
|
||||||
|
let prefs_dialog = Rc::new(PrefsDialog::new(builder_prefs_dialog));
|
||||||
|
init_prefs_dialog(&appstate, &prefs_dialog);
|
||||||
|
{
|
||||||
|
let prefs_dialog_w = &prefs_dialog.prefs_dialog;
|
||||||
|
prefs_dialog_w.set_transient_for(&appstate.gui.popup_menu.menu_window);
|
||||||
|
prefs_dialog_w.run();
|
||||||
|
prefs_dialog_w.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_prefs_dialog_show(appstate: &AppS) {
|
/* TODO: do the references get dropped when the dialog window is gone? */
|
||||||
let card_combo = &appstate.gui.prefs_dialog.card_combo;
|
pub fn init_prefs_dialog(appstate: &Rc<AppS>, prefs_dialog: &Rc<PrefsDialog>) {
|
||||||
let chan_combo = &appstate.gui.prefs_dialog.chan_combo;
|
|
||||||
|
/* prefs_dialog.connect_show */
|
||||||
|
{
|
||||||
|
let apps = appstate.clone();
|
||||||
|
let pd = prefs_dialog.clone();
|
||||||
|
prefs_dialog.clone().prefs_dialog.connect_show(move |_| { on_prefs_dialog_show(&apps, &pd); });
|
||||||
|
}
|
||||||
|
|
||||||
|
/* card_combo.connect_changed */
|
||||||
|
{
|
||||||
|
let apps = appstate.clone();
|
||||||
|
let card_combo = &prefs_dialog.card_combo;
|
||||||
|
let pd = prefs_dialog.clone();
|
||||||
|
|
||||||
|
card_combo.connect_changed(move |_| {
|
||||||
|
on_card_combo_changed(&apps, &pd);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/* card_combo.connect_changed */
|
||||||
|
{
|
||||||
|
let apps = appstate.clone();
|
||||||
|
let chan_combo = &prefs_dialog.chan_combo;
|
||||||
|
let pd = prefs_dialog.clone();
|
||||||
|
|
||||||
|
chan_combo.connect_changed(move |_| {
|
||||||
|
on_chan_combo_changed(&apps, &pd);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn on_prefs_dialog_show(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||||
|
let card_combo = &prefs_dialog.card_combo;
|
||||||
|
let chan_combo = &prefs_dialog.chan_combo;
|
||||||
let acard = appstate.audio.acard.borrow();
|
let acard = appstate.audio.acard.borrow();
|
||||||
|
|
||||||
|
|
||||||
@ -79,17 +105,15 @@ fn on_prefs_dialog_show(appstate: &AppS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_card_combo_changed(appstate: &AppS) {
|
fn on_card_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||||
let card_combo = &appstate.gui.prefs_dialog.card_combo;
|
let card_combo = &prefs_dialog.card_combo;
|
||||||
let chan_combo = &appstate.gui.prefs_dialog.chan_combo;
|
let chan_combo = &prefs_dialog.chan_combo;
|
||||||
let active_card_item =
|
let active_card_item =
|
||||||
try_w!(card_combo.get_active_text().ok_or("No active Card item found"));
|
try_w!(card_combo.get_active_text().ok_or("No active Card item found"));
|
||||||
let active_chan_item =
|
let active_chan_item = chan_combo.get_active_id();
|
||||||
chan_combo.get_active_id();
|
|
||||||
let cur_card_name = {
|
let cur_card_name = {
|
||||||
let acard = appstate.audio.acard.borrow();
|
let acard = appstate.audio.acard.borrow();
|
||||||
try_w!(acard.card_name(),
|
try_w!(acard.card_name(), "Can't get current card name!")
|
||||||
"Can't get current card name!")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if active_card_item != cur_card_name {
|
if active_card_item != cur_card_name {
|
||||||
@ -98,9 +122,9 @@ fn on_card_combo_changed(appstate: &AppS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn on_chan_combo_changed(appstate: &AppS) {
|
fn on_chan_combo_changed(appstate: &AppS, prefs_dialog: &PrefsDialog) {
|
||||||
let card_combo = &appstate.gui.prefs_dialog.card_combo;
|
let card_combo = &prefs_dialog.card_combo;
|
||||||
let chan_combo = &appstate.gui.prefs_dialog.chan_combo;
|
let chan_combo = &prefs_dialog.chan_combo;
|
||||||
let active_chan_item =
|
let active_chan_item =
|
||||||
try_w!(chan_combo.get_active_text().ok_or("No active Chan item found"));
|
try_w!(chan_combo.get_active_text().ok_or("No active Chan item found"));
|
||||||
let cur_card_name = {
|
let cur_card_name = {
|
||||||
@ -116,4 +140,3 @@ fn on_chan_combo_changed(appstate: &AppS) {
|
|||||||
appstate.audio.switch_acard(cur_card_name, Some(active_chan_item));
|
appstate.audio.switch_acard(cur_card_name, Some(active_chan_item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user