[fractal/multi-account] Change between logged-in users
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/multi-account] Change between logged-in users
- Date: Tue, 13 Jul 2021 15:31:42 +0000 (UTC)
commit acb586d502e1b4a96e972645d122abbd0320beb2
Author: Alejandro Domínguez <adomu net-c com>
Date: Tue Jul 13 17:31:24 2021 +0200
Change between logged-in users
src/session/mod.rs | 7 ++++---
src/session/sidebar/sidebar.rs | 20 +++++++++++++-------
src/window.rs | 21 ++++++++++++++++++---
3 files changed, 35 insertions(+), 13 deletions(-)
---
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 5e17f31e..35207194 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -21,11 +21,12 @@ use crate::Error;
use crate::RUNTIME;
use crate::session::content::ContentType;
+use crate::Window;
use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
-use gtk::{gio, glib, glib::clone, glib::SyncSender, CompositeTemplate, SelectionModel};
+use gtk::{gio, glib, glib::clone, glib::SyncSender, CompositeTemplate};
use gtk_macros::send;
use log::error;
use matrix_sdk::ruma::{
@@ -432,8 +433,8 @@ impl Session {
self.room_list().handle_response_rooms(response.rooms);
}
- pub fn set_logged_in_users(&self, logged_in_users: &SelectionModel) {
+ pub fn set_logged_in_users(&self, window: &Window) {
let priv_ = &imp::Session::from_instance(self);
- priv_.sidebar.set_logged_in_users(logged_in_users);
+ priv_.sidebar.set_logged_in_users(window);
}
}
diff --git a/src/session/sidebar/sidebar.rs b/src/session/sidebar/sidebar.rs
index d56d29c8..b1d418b6 100644
--- a/src/session/sidebar/sidebar.rs
+++ b/src/session/sidebar/sidebar.rs
@@ -1,12 +1,13 @@
use adw::subclass::prelude::BinImpl;
-use gtk::{gio, glib, prelude::*, subclass::prelude::*, CompositeTemplate, SelectionModel};
+use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*, CompositeTemplate};
use crate::session::{
content::ContentType,
room::Room,
sidebar::{Category, Entry, ItemList, RoomRow, Row, Selection},
- RoomList,
+ RoomList, User,
};
+use crate::Window;
use super::account_switcher::AccountSwitcher;
@@ -259,12 +260,17 @@ impl Sidebar {
self.notify("selected-room");
}
- pub fn set_logged_in_users(&self, logged_in_users: &SelectionModel) {
+ pub fn set_logged_in_users(&self, window: &Window) {
let priv_ = imp::Sidebar::from_instance(self);
- priv_
- .account_switcher
- .users()
- .set_model(Some(logged_in_users));
+ let users = priv_.account_switcher.users();
+ users.set_model(Some(&window.stack_pages()));
+ users.connect_activate(clone!(@weak window => move |list, index| {
+ list.model()
+ .and_then(|m| m.item(index))
+ .and_then(|obj| obj.downcast::<User>().ok())
+ .map(|user| user.user_id())
+ .map(|user_id| window.switch_to_session(&user_id));
+ }));
}
}
diff --git a/src/window.rs b/src/window.rs
index 07713a99..f449fcb4 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -8,8 +8,9 @@ use gio::PropertyAction;
use glib::signal::Inhibit;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
-use gtk::{gio, glib, glib::clone, CompositeTemplate};
+use gtk::{gio, glib, glib::clone, CompositeTemplate, SelectionModel};
use log::warn;
+use matrix_sdk::ruma::identifiers::UserId;
mod imp {
use super::*;
@@ -96,8 +97,10 @@ impl Window {
fn add_session(&self, session: &Session) {
let priv_ = &imp::Window::from_instance(self);
- session.set_logged_in_users(&priv_.main_stack.pages());
- priv_.main_stack.add_child(session);
+ session.set_logged_in_users(self);
+ priv_
+ .main_stack
+ .add_named(session, Some(session.user().user_id().as_str()));
priv_.main_stack.set_visible_child(session);
self.install_session_actions(session);
}
@@ -149,4 +152,16 @@ impl Window {
self.set_default_size(width, height);
self.set_property("maximized", &is_maximized).unwrap();
}
+
+ pub fn stack_pages(&self) -> SelectionModel {
+ let priv_ = &imp::Window::from_instance(self);
+
+ priv_.main_stack.pages()
+ }
+
+ pub fn switch_to_session(&self, user_id: &UserId) {
+ let priv_ = &imp::Window::from_instance(self);
+
+ priv_.main_stack.set_visible_child_name(user_id.as_str());
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]