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-02 16:11:56 +00:00
|
|
|
|
2017-07-10 19:07:59 +00:00
|
|
|
#[cfg(feature = "notify")]
|
|
|
|
use notif::*;
|
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-07-10 19:07:59 +00:00
|
|
|
#[cfg(feature = "notify")]
|
|
|
|
pub notif: Notif,
|
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 =
|
2017-07-08 00:38:49 +00:00
|
|
|
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-07-08 00:38:49 +00:00
|
|
|
let card_name = prefs.borrow()
|
|
|
|
.device_prefs
|
|
|
|
.card
|
|
|
|
.clone();
|
|
|
|
let chan_name = prefs.borrow()
|
|
|
|
.device_prefs
|
|
|
|
.channel
|
|
|
|
.clone();
|
2017-07-10 19:07:59 +00:00
|
|
|
// TODO: better error handling
|
|
|
|
#[cfg(feature = "notify")]
|
|
|
|
let notif = Notif::new(&prefs.borrow()).unwrap();
|
2017-07-08 22:14:49 +00:00
|
|
|
|
2017-06-30 15:24:26 +00:00
|
|
|
return AppS {
|
2017-07-07 20:10:45 +00:00
|
|
|
_cant_construct: (),
|
2017-07-08 22:14:49 +00:00
|
|
|
gui,
|
2017-07-08 00:38:49 +00:00
|
|
|
audio: Audio::new(Some(card_name), Some(chan_name)).unwrap(),
|
2017-07-08 22:14:49 +00:00
|
|
|
prefs,
|
2017-07-10 19:07:59 +00:00
|
|
|
#[cfg(feature = "notify")]
|
|
|
|
notif,
|
2017-07-07 20:10:45 +00:00
|
|
|
};
|
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 15:00:04 +00:00
|
|
|
}
|