window: Allow to get a Session by ID
This commit is contained in:
parent
9122a7f926
commit
642790c289
2 changed files with 30 additions and 4 deletions
|
@ -188,6 +188,13 @@ mod imp {
|
||||||
fn properties() -> &'static [glib::ParamSpec] {
|
fn properties() -> &'static [glib::ParamSpec] {
|
||||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
|
||||||
vec![
|
vec![
|
||||||
|
glib::ParamSpecString::new(
|
||||||
|
"session-id",
|
||||||
|
"Session ID",
|
||||||
|
"The unique ID of this session",
|
||||||
|
None,
|
||||||
|
glib::ParamFlags::READABLE,
|
||||||
|
),
|
||||||
glib::ParamSpecObject::new(
|
glib::ParamSpecObject::new(
|
||||||
"item-list",
|
"item-list",
|
||||||
"Item List",
|
"Item List",
|
||||||
|
@ -217,6 +224,7 @@ mod imp {
|
||||||
|
|
||||||
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
|
||||||
match pspec.name() {
|
match pspec.name() {
|
||||||
|
"session-id" => obj.session_id().to_value(),
|
||||||
"item-list" => obj.item_list().to_value(),
|
"item-list" => obj.item_list().to_value(),
|
||||||
"user" => obj.user().to_value(),
|
"user" => obj.user().to_value(),
|
||||||
"offline" => obj.is_offline().to_value(),
|
"offline" => obj.is_offline().to_value(),
|
||||||
|
@ -289,8 +297,8 @@ impl Session {
|
||||||
glib::Object::new(&[]).expect("Failed to create Session")
|
glib::Object::new(&[]).expect("Failed to create Session")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn session_id(&self) -> &str {
|
pub fn session_id(&self) -> Option<&str> {
|
||||||
self.imp().info.get().unwrap().id()
|
self.imp().info.get().map(|info| info.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn select_room(&self, room: Option<Room>) {
|
pub fn select_room(&self, room: Option<Room>) {
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl Window {
|
||||||
let priv_ = &self.imp();
|
let priv_ = &self.imp();
|
||||||
let prev_has_sessions = self.has_sessions();
|
let prev_has_sessions = self.has_sessions();
|
||||||
|
|
||||||
priv_.sessions.add_child(session);
|
priv_.sessions.add_named(session, session.session_id());
|
||||||
priv_.sessions.set_visible_child(session);
|
priv_.sessions.set_visible_child(session);
|
||||||
// We need to grab the focus so that keyboard shortcuts work
|
// We need to grab the focus so that keyboard shortcuts work
|
||||||
session.grab_focus();
|
session.grab_focus();
|
||||||
|
@ -199,7 +199,7 @@ impl Window {
|
||||||
|
|
||||||
// If the session was a new login that was logged out before being ready, go
|
// If the session was a new login that was logged out before being ready, go
|
||||||
// back to the login screen.
|
// back to the login screen.
|
||||||
if priv_.login.current_session_id().as_deref() == Some(session.session_id()) {
|
if priv_.login.current_session_id().as_deref() == session.session_id() {
|
||||||
priv_.login.restore_client();
|
priv_.login.restore_client();
|
||||||
self.switch_to_login_page();
|
self.switch_to_login_page();
|
||||||
} else if let Some(child) = priv_.sessions.first_child() {
|
} else if let Some(child) = priv_.sessions.first_child() {
|
||||||
|
@ -256,6 +256,24 @@ impl Window {
|
||||||
self.imp().sessions.pages().n_items() > 0
|
self.imp().sessions.pages().n_items() > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the session with the given ID.
|
||||||
|
pub fn session_by_id(&self, session_id: &str) -> Option<Session> {
|
||||||
|
self.imp()
|
||||||
|
.sessions
|
||||||
|
.child_by_name(session_id)
|
||||||
|
.and_then(|w| w.downcast().ok())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The ID of the currently visible session, if any.
|
||||||
|
pub fn current_session_id(&self) -> Option<String> {
|
||||||
|
let priv_ = self.imp();
|
||||||
|
priv_
|
||||||
|
.main_stack
|
||||||
|
.visible_child()
|
||||||
|
.filter(|child| child == priv_.sessions.upcast_ref::<gtk::Widget>())?;
|
||||||
|
priv_.sessions.visible_child_name().map(Into::into)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
|
pub fn save_window_size(&self) -> Result<(), glib::BoolError> {
|
||||||
let settings = Application::default().settings();
|
let settings = Application::default().settings();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue