pnmixer-rust/src/ui_entry.rs

101 lines
2.8 KiB
Rust
Raw Normal View History

2017-06-29 12:55:07 +00:00
use app_state::*;
2017-07-08 22:14:49 +00:00
use audio::{AudioUser, AudioSignal};
use gtk::DialogExt;
use gtk::MessageDialogExt;
use gtk::WidgetExt;
use gtk::WindowExt;
2017-07-07 10:03:53 +00:00
use gtk;
2017-07-08 22:14:49 +00:00
use gtk_sys::{GTK_DIALOG_DESTROY_WITH_PARENT, GTK_RESPONSE_YES};
use notif::*;
2017-07-07 10:03:53 +00:00
use prefs::*;
2017-07-06 22:28:55 +00:00
use std::cell::RefCell;
2017-07-07 10:03:53 +00:00
use std::rc::Rc;
2017-07-08 22:14:49 +00:00
use support_audio::*;
2017-07-01 14:55:35 +00:00
use ui_popup_menu::*;
2017-06-29 12:55:07 +00:00
use ui_popup_window::*;
2017-07-08 00:38:49 +00:00
use ui_prefs_dialog::*;
2017-06-29 12:55:07 +00:00
use ui_tray_icon::*;
2017-07-08 00:38:49 +00:00
2017-06-29 12:55:07 +00:00
2017-07-07 10:03:53 +00:00
pub struct Gui {
_cant_construct: (),
pub tray_icon: TrayIcon,
pub popup_window: PopupWindow,
pub popup_menu: PopupMenu,
/* prefs_dialog is dynamically created and destroyed */
pub prefs_dialog: RefCell<Option<PrefsDialog>>,
}
impl Gui {
2017-07-07 20:10:45 +00:00
pub fn new(builder_popup_window: gtk::Builder,
builder_popup_menu: gtk::Builder,
prefs: &Prefs)
-> Gui {
2017-07-07 10:03:53 +00:00
return Gui {
2017-07-07 20:10:45 +00:00
_cant_construct: (),
tray_icon: TrayIcon::new(prefs).unwrap(),
popup_window: PopupWindow::new(builder_popup_window),
popup_menu: PopupMenu::new(builder_popup_menu),
prefs_dialog: RefCell::new(None),
};
2017-07-07 10:03:53 +00:00
}
}
2017-06-30 15:24:26 +00:00
pub fn init(appstate: Rc<AppS>) {
2017-06-30 19:10:33 +00:00
{
2017-07-08 22:14:49 +00:00
/* "global" audio signal handler */
2017-07-08 00:38:49 +00:00
let apps = appstate.clone();
appstate.audio.connect_handler(
Box::new(move |s, u| match (s, u) {
2017-07-08 22:14:49 +00:00
(AudioSignal::CardDisconnected, _) => {
try_w!(audio_reload(&apps.audio,
&apps.prefs.borrow(),
AudioUser::Unknown));
},
(AudioSignal::CardError, _) => {
if run_audio_error_dialog(&apps.gui.popup_menu.menu_window) == (GTK_RESPONSE_YES as i32) {
try_w!(audio_reload(&apps.audio,
&apps.prefs.borrow(),
AudioUser::Unknown));
}
},
_ => (),
}
));
2017-06-30 19:10:33 +00:00
}
2017-06-30 15:24:26 +00:00
2017-06-30 19:10:33 +00:00
init_tray_icon(appstate.clone());
init_popup_window(appstate.clone());
2017-07-01 14:55:35 +00:00
init_popup_menu(appstate.clone());
2017-07-08 00:38:49 +00:00
init_prefs_callback(appstate.clone());
2017-06-29 12:55:07 +00:00
}
2017-07-08 22:14:49 +00:00
fn run_audio_error_dialog(parent: &gtk::Window) -> i32 {
error!("Connection with audio failed, you probably need to restart pnmixer.");
let dialog = gtk::MessageDialog::new(
Some(parent),
gtk::DIALOG_DESTROY_WITH_PARENT,
gtk::MessageType::Error,
gtk::ButtonsType::YesNo,
"Warning: Connection to sound system failed."
);
dialog.set_property_secondary_text(Some("Do you want to re-initialize the audio connection ?
If you do not, you will either need to restart PNMixer
or select the 'Reload Audio' option in the right-click
menu in order for PNMixer to function."));
dialog.set_title("PNMixer-rs Error");
let resp = dialog.run();
dialog.destroy();
return resp;
}