pub mod imp;
use gettextrs::pgettext;
use gtk::{
glib::{self},
subclass::prelude::ObjectSubclassIsExt,
};
use super::unit_control_panel::UnitControlPanel;
glib::wrapper! {
pub struct ControlActionDialog(ObjectSubclass<imp::EnableUnitDialogImp>)
@extends adw::Window, gtk::Window, gtk::Widget,
@implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget,
gtk::Native, gtk::Root, gtk::ShortcutManager;
}
impl ControlActionDialog {
pub fn new(unit_control: &UnitControlPanel, action_type: ControlActionType) -> Self {
let obj: ControlActionDialog = glib::Object::new();
let imp = obj.imp();
imp.set_app_window(unit_control, action_type);
obj
}
}
#[derive(Debug, Copy, Clone)]
pub enum ControlActionType {
EnableUnitFiles,
MaskUnit,
Preset,
DisableUnitFiles,
Reenable,
Link,
}
impl ControlActionType {
pub fn code(&self) -> &str {
match self {
ControlActionType::EnableUnitFiles => "Enable Unit File",
ControlActionType::MaskUnit => "Mask Unit",
ControlActionType::Preset => "Preset Unit File",
ControlActionType::Reenable => "Reenable Unit File",
ControlActionType::DisableUnitFiles => "Disable Unit File",
ControlActionType::Link => "Link Unit File",
}
}
pub fn title(&self) -> String {
match self {
ControlActionType::EnableUnitFiles => pgettext("action unit file", "Enable Unit File"),
ControlActionType::MaskUnit => pgettext("action unit file", "Mask Unit"),
ControlActionType::Preset => pgettext("action unit file", "Preset Unit File"),
ControlActionType::Reenable => pgettext("action unit file", "Reenable Unit File"),
ControlActionType::DisableUnitFiles => {
pgettext("action unit file", "Disable Unit File")
}
ControlActionType::Link => pgettext("action unit file", "Link Unit File"),
}
}
pub fn first_group_title(&self) -> String {
match self {
ControlActionType::EnableUnitFiles => pgettext("action unit file", "Enable"),
ControlActionType::DisableUnitFiles => pgettext("action unit file", "Disable"),
ControlActionType::MaskUnit => pgettext("action unit file", "Mask"),
_ => String::new(),
}
}
pub fn after_group_title(&self) -> String {
match self {
ControlActionType::EnableUnitFiles => pgettext("action unit file", "Start"),
ControlActionType::DisableUnitFiles | ControlActionType::MaskUnit => {
pgettext("action unit file", "Stop")
}
_ => String::new(),
}
}
pub fn dialog_subtitle(&self) -> bool {
!matches!(
self,
ControlActionType::EnableUnitFiles | ControlActionType::Link
)
}
fn unit_file_entry_visible(&self) -> bool {
matches!(
self,
ControlActionType::EnableUnitFiles | ControlActionType::Link
)
}
fn dbus_level_combo_visible(&self) -> bool {
matches!(
self,
ControlActionType::EnableUnitFiles | ControlActionType::Link
)
}
fn portable_switch_visible(&self) -> bool {
matches!(
self,
ControlActionType::EnableUnitFiles | ControlActionType::DisableUnitFiles
)
}
fn after_action_group_visible(&self) -> bool {
matches!(
self,
ControlActionType::EnableUnitFiles
| ControlActionType::MaskUnit
| ControlActionType::DisableUnitFiles
)
}
fn send_action_label(&self) -> String {
match self {
ControlActionType::EnableUnitFiles => pgettext("action unit file", "Enable"),
ControlActionType::MaskUnit => pgettext("action unit file", "Mask"),
ControlActionType::Preset => pgettext("action unit file", "Preset"),
ControlActionType::DisableUnitFiles => pgettext("action unit file", "Disable"),
ControlActionType::Reenable => pgettext("action unit file", "Reenable"),
ControlActionType::Link => pgettext("action unit file", "Link"),
}
}
fn run_stop_now(&self) -> (String, String) {
match self {
ControlActionType::EnableUnitFiles => (
pgettext("action unit file", "Run now"),
pgettext("action unit file", "Start Unit just after being enabled"),
),
ControlActionType::MaskUnit | ControlActionType::DisableUnitFiles => (
pgettext("action unit file", "Stop now"),
pgettext(
"action unit file",
"Ensure that the unit will also be stopped",
),
),
_ => (String::new(), String::new()),
}
}
fn run_stop_now_mode(&self) -> (String, String) {
match self {
ControlActionType::EnableUnitFiles => (
pgettext("action unit file", "Run mode"),
pgettext("action unit file", "Starting mode options"),
),
ControlActionType::MaskUnit | ControlActionType::DisableUnitFiles => (
pgettext("action unit file", "Stop mode"),
pgettext("action unit file", "Stoping mode options"),
),
_ => (String::new(), String::new()),
}
}
fn method_name(&self) -> String {
self.title()
}
}