pnmixer-rust/src/ui_popup_menu.rs

179 lines
5.1 KiB
Rust
Raw Normal View History

2017-07-01 14:55:35 +00:00
use app_state::*;
2017-07-07 15:00:04 +00:00
use audio::{AudioUser, AudioSignal};
2017-07-01 14:55:35 +00:00
use gtk::prelude::*;
use gtk;
2017-07-07 10:03:53 +00:00
use std::rc::Rc;
2017-07-07 15:00:04 +00:00
use support_cmd::*;
2017-07-02 17:08:17 +00:00
use ui_prefs_dialog::*;
2017-07-01 14:55:35 +00:00
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
2017-07-07 10:03:53 +00:00
2017-07-07 20:10:45 +00:00
create_builder_item!(PopupMenu,
menu_window: gtk::Window,
menubar: gtk::MenuBar,
menu: gtk::Menu,
about_item: gtk::MenuItem,
mixer_item: gtk::MenuItem,
mute_item: gtk::MenuItem,
mute_check: gtk::CheckButton,
prefs_item: gtk::MenuItem,
quit_item: gtk::MenuItem,
reload_item: gtk::MenuItem);
2017-07-07 10:03:53 +00:00
2017-07-01 14:55:35 +00:00
pub fn init_popup_menu(appstate: Rc<AppS>) {
2017-07-07 15:00:04 +00:00
/* audio.connect_handler */
{
let apps = appstate.clone();
appstate.audio.connect_handler(Box::new(move |s, u| {
/* skip if window is hidden */
2017-07-07 20:10:45 +00:00
if !apps.gui
.popup_menu
.menu
.get_visible() {
2017-07-07 15:00:04 +00:00
return;
}
match (s, u) {
2017-07-07 23:35:13 +00:00
(_, _) => set_mute_check(&apps)
2017-07-07 15:00:04 +00:00
}
}));
}
/* popup_menu.menu.connect_show */
{
let apps = appstate.clone();
2017-07-07 20:10:45 +00:00
appstate.gui
.popup_menu
.menu
.connect_show(move |_| {
2017-07-07 23:35:13 +00:00
set_mute_check(&apps)
2017-07-07 20:10:45 +00:00
});
2017-07-07 15:00:04 +00:00
}
/* mixer_item.connect_activate_link */
{
let apps = appstate.clone();
let mixer_item = &appstate.gui.popup_menu.mixer_item;
mixer_item.connect_activate(move |_| {
try_w!(execute_vol_control_command(&apps.prefs.borrow()));
});
}
2017-07-01 14:55:35 +00:00
2017-07-07 23:35:13 +00:00
/* mute_item.connect_activate_link */
2017-07-01 14:55:35 +00:00
{
let apps = appstate.clone();
2017-07-07 15:00:04 +00:00
let mute_item = &appstate.gui.popup_menu.mute_item;
mute_item.connect_activate(move |_| {
2017-07-07 23:35:13 +00:00
if apps.audio.has_mute() {
try_w!(apps.audio.toggle_mute(AudioUser::Popup));
}
2017-07-07 15:00:04 +00:00
});
2017-07-01 14:55:35 +00:00
}
2017-07-02 16:11:56 +00:00
/* about_item.connect_activate_link */
{
2017-07-07 15:00:04 +00:00
let apps = appstate.clone();
let about_item = &appstate.gui.popup_menu.about_item;
2017-07-07 20:10:45 +00:00
about_item.connect_activate(move |_| {
on_about_item_activate(&apps);
});
2017-07-07 15:00:04 +00:00
}
2017-07-07 23:35:13 +00:00
/* prefs_item.connect_activate_link */
2017-07-07 15:00:04 +00:00
{
let apps = appstate.clone();
let prefs_item = &appstate.gui.popup_menu.prefs_item;
2017-07-07 20:10:45 +00:00
prefs_item.connect_activate(move |_| {
on_prefs_item_activate(&apps);
});
}
/* quit_item.connect_activate_link */
{
let quit_item = &appstate.gui.popup_menu.quit_item;
quit_item.connect_activate(|_| {
gtk::main_quit();
});
2017-07-02 16:11:56 +00:00
}
2017-07-01 14:55:35 +00:00
}
fn on_about_item_activate(appstate: &AppS) {
let popup_menu = &appstate.gui.popup_menu.menu_window;
let about_dialog = create_about_dialog();
about_dialog.set_skip_taskbar_hint(true);
about_dialog.set_transient_for(popup_menu);
about_dialog.run();
about_dialog.destroy();
}
fn create_about_dialog() -> gtk::AboutDialog {
let about_dialog: gtk::AboutDialog = gtk::AboutDialog::new();
2017-07-04 14:54:16 +00:00
about_dialog.set_license(Some(
"PNMixer is free software; you can redistribute it and/or modify it
2017-07-01 14:55:35 +00:00
under the terms of the GNU General Public License v3 as published
by the Free Software Foundation.
PNMixer is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with PNMixer; if not, write to the Free Software Foundation,
2017-07-04 14:54:16 +00:00
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.",
));
2017-07-01 14:55:35 +00:00
about_dialog.set_copyright(Some("Copyright © 2017 Julian Ospald"));
about_dialog.set_authors(&["Julian Ospald"]);
about_dialog.set_artists(&["Paul Davey"]);
about_dialog.set_program_name("pnmixer-rs");
about_dialog.set_logo_icon_name("pnmixer");
about_dialog.set_version(VERSION);
about_dialog.set_website("https://github.com/hasufell/pnmixer-rust");
about_dialog.set_comments("A mixer for the system tray");
return about_dialog;
}
2017-07-02 16:11:56 +00:00
2017-07-07 15:00:04 +00:00
fn on_prefs_item_activate(appstate: &Rc<AppS>) {
2017-07-02 16:11:56 +00:00
/* TODO: only create if needed */
2017-07-02 17:08:17 +00:00
show_prefs_dialog(appstate);
2017-07-02 16:11:56 +00:00
}
2017-07-07 23:35:13 +00:00
fn set_mute_check(apps: &Rc<AppS>) {
let mute_check = &apps.gui
.popup_menu
.mute_check;
let m_muted = apps.audio.get_mute();
match m_muted {
Ok(muted) => {
mute_check
.set_sensitive(false);
mute_check
.set_active(muted);
mute_check.set_tooltip_text(
"");
},
Err(_) => {
mute_check
.set_active(true);
mute_check
.set_sensitive(false);
mute_check.set_tooltip_text(
"Soundcard has no mute switch",
);
}
}
}