fractal/session/model/sidebar_data/section/
name.rsuse std::fmt;
use gettextrs::gettext;
use gtk::glib;
use serde::{Deserialize, Serialize};
use crate::session::model::{RoomCategory, TargetRoomCategory};
#[derive(
Debug, Default, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, glib::Enum, Serialize, Deserialize,
)]
#[enum_type(name = "SidebarSectionName")]
#[serde(rename_all = "kebab-case")]
pub enum SidebarSectionName {
VerificationRequest,
Invited,
Favorite,
#[default]
Normal,
LowPriority,
Left,
}
impl SidebarSectionName {
pub(crate) fn from_room_category(category: RoomCategory) -> Option<Self> {
let name = match category {
RoomCategory::Invited => Self::Invited,
RoomCategory::Favorite => Self::Favorite,
RoomCategory::Normal => Self::Normal,
RoomCategory::LowPriority => Self::LowPriority,
RoomCategory::Left => Self::Left,
RoomCategory::Outdated | RoomCategory::Space | RoomCategory::Ignored => return None,
};
Some(name)
}
pub(crate) fn into_room_category(self) -> Option<RoomCategory> {
let category = match self {
Self::VerificationRequest => return None,
Self::Invited => RoomCategory::Invited,
Self::Favorite => RoomCategory::Favorite,
Self::Normal => RoomCategory::Normal,
Self::LowPriority => RoomCategory::LowPriority,
Self::Left => RoomCategory::Left,
};
Some(category)
}
pub(crate) fn into_target_room_category(self) -> Option<TargetRoomCategory> {
let category = match self {
Self::VerificationRequest | Self::Invited => return None,
Self::Favorite => TargetRoomCategory::Favorite,
Self::Normal => TargetRoomCategory::Normal,
Self::LowPriority => TargetRoomCategory::LowPriority,
Self::Left => TargetRoomCategory::Left,
};
Some(category)
}
}
impl fmt::Display for SidebarSectionName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let label = match self {
SidebarSectionName::VerificationRequest => gettext("Verifications"),
SidebarSectionName::Invited => gettext("Invited"),
SidebarSectionName::Favorite => gettext("Favorites"),
SidebarSectionName::Normal => gettext("Rooms"),
SidebarSectionName::LowPriority => gettext("Low Priority"),
SidebarSectionName::Left => gettext("Historical"),
};
f.write_str(&label)
}
}