pnmixer-rust/src/app_state.rs

61 lines
1.6 KiB
Rust
Raw Normal View History

2017-07-01 22:03:21 +00:00
use audio::Audio;
2017-07-07 10:03:53 +00:00
use errors::*;
2017-07-05 22:14:24 +00:00
use gtk;
2017-07-06 22:28:55 +00:00
use prefs::*;
2017-07-05 22:14:24 +00:00
use std::cell::RefCell;
2017-07-07 10:03:53 +00:00
use ui_entry::Gui;
2017-07-07 15:00:04 +00:00
use ui_prefs_dialog::show_prefs_dialog;
2017-07-02 16:11:56 +00:00
2017-06-27 22:23:12 +00:00
2017-07-07 10:03:53 +00:00
// TODO: notify popups
2017-06-28 15:53:19 +00:00
2017-06-30 15:24:26 +00:00
// TODO: destructors
2017-06-29 12:55:07 +00:00
2017-06-29 13:50:24 +00:00
// TODO: glade stuff, config, alsacard
2017-06-27 22:23:12 +00:00
pub struct AppS {
2017-07-07 10:03:53 +00:00
_cant_construct: (),
2017-06-30 15:24:26 +00:00
pub gui: Gui,
2017-07-01 22:03:21 +00:00
pub audio: Audio,
2017-07-05 22:14:24 +00:00
pub prefs: RefCell<Prefs>,
2017-06-30 15:24:26 +00:00
}
impl AppS {
pub fn new() -> AppS {
2017-07-07 20:10:45 +00:00
let builder_popup_window =
gtk::Builder::new_from_string(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/data/ui/popup-window.glade")));
let builder_popup_menu = gtk::Builder::new_from_string(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/data/ui/popup-menu.glade")));
2017-07-05 22:14:24 +00:00
let prefs = RefCell::new(Prefs::new().unwrap());
let gui =
Gui::new(builder_popup_window, builder_popup_menu, &prefs.borrow());
2017-07-02 17:08:17 +00:00
2017-06-30 15:24:26 +00:00
return AppS {
2017-07-07 20:10:45 +00:00
_cant_construct: (),
gui: gui,
audio: Audio::new(None, Some(String::from("Master")))
.unwrap(),
prefs: prefs,
};
2017-06-30 15:24:26 +00:00
}
2017-07-07 15:00:04 +00:00
/* some functions that need to be easily accessible */
2017-07-07 10:03:53 +00:00
pub fn update_tray_icon(&self) -> Result<()> {
debug!("Update tray icon!");
2017-07-07 20:10:45 +00:00
return self.gui.tray_icon.update_all(&self.prefs.borrow(),
&self.audio,
None);
2017-06-30 15:24:26 +00:00
}
2017-07-06 22:28:55 +00:00
2017-07-07 10:03:53 +00:00
pub fn update_popup_window(&self) -> Result<()> {
debug!("Update PopupWindow!");
return self.gui.popup_window.update(&self.audio);
2017-07-06 14:53:19 +00:00
}
2017-07-07 10:03:53 +00:00
2017-07-07 15:00:04 +00:00
pub fn show_preferences(&self) {
// show_prefs_dialog(self);
}
}