[fractal/multi-account: 5/6] Add account switcher
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/multi-account: 5/6] Add account switcher
- Date: Mon, 2 Aug 2021 10:36:37 +0000 (UTC)
commit 339a830c6e18559dc49bacb4257eccbb1e3d2cbf
Author: Alejandro Domínguez <adomu net-c com>
Date: Tue Jul 13 15:34:37 2021 +0200
Add account switcher
data/resources/resources.gresource.xml | 1 +
data/resources/style.css | 20 +++++++
data/resources/ui/sidebar-account-switcher-item.ui | 64 ++++++++++++++++++++++
data/resources/ui/sidebar.ui | 51 +++++++++++++++++
src/session/mod.rs | 7 ++-
src/session/sidebar/sidebar.rs | 10 +++-
src/window.rs | 1 +
7 files changed, 152 insertions(+), 2 deletions(-)
---
diff --git a/data/resources/resources.gresource.xml b/data/resources/resources.gresource.xml
index 2a6d9825..54ac0678 100644
--- a/data/resources/resources.gresource.xml
+++ b/data/resources/resources.gresource.xml
@@ -18,6 +18,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="login.ui">ui/login.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="session.ui">ui/session.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="sidebar.ui">ui/sidebar.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks"
alias="sidebar-account-switcher-item.ui">ui/sidebar-account-switcher-item.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="sidebar-item.ui">ui/sidebar-item.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="sidebar-category-row.ui">ui/sidebar-category-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks"
alias="sidebar-entry-row.ui">ui/sidebar-entry-row.ui</file>
diff --git a/data/resources/style.css b/data/resources/style.css
index ea4085e7..4431baaa 100644
--- a/data/resources/style.css
+++ b/data/resources/style.css
@@ -40,6 +40,26 @@ headerbar.flat {
border: none;
}
+/* Account switcher */
+#account-switcher row, #new-login {
+ border-radius: 10px;
+ margin-top: 3px;
+ margin-bottom: 3px;
+}
+
+#account-switcher row box, #new-login box {
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+#account-switcher .selected-account avatar {
+ border: 2px solid @accent_bg_color;
+}
+
+#account-switcher .user-id {
+ font-size: 12px;
+}
+
/* Sidebar */
.sidebar row {
padding-left: 10px;
diff --git a/data/resources/ui/sidebar-account-switcher-item.ui
b/data/resources/ui/sidebar-account-switcher-item.ui
new file mode 100644
index 00000000..0bd53e93
--- /dev/null
+++ b/data/resources/ui/sidebar-account-switcher-item.ui
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <template class="GtkListItem">
+ <property name="child">
+ <object class="GtkBox">
+ <property name="spacing">10</property>
+ <child>
+ <object class="ComponentsAvatar">
+ <property name="size">40</property>
+ <binding name="item">
+ <lookup name="avatar" type="User">
+ <lookup name="user" type="Session">
+ <lookup name="child" type="GtkStackPage">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0.0</property>
+ <binding name="label">
+ <lookup name="display-name" type="User">
+ <lookup name="user" type="Session">
+ <lookup name="child" type="GtkStackPage">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </lookup>
+ </lookup>
+ </binding>
+ <style>
+ <class name="bold" />
+ </style>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0.0</property>
+ <binding name="label">
+ <lookup name="user-id" type="User">
+ <lookup name="user" type="Session">
+ <lookup name="child" type="GtkStackPage">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </lookup>
+ </lookup>
+ </binding>
+ <style>
+ <class name="dim-label" />
+ <class name="user-id" />
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
+ </template>
+</interface>
diff --git a/data/resources/ui/sidebar.ui b/data/resources/ui/sidebar.ui
index 5de728b5..7dbc621b 100644
--- a/data/resources/ui/sidebar.ui
+++ b/data/resources/ui/sidebar.ui
@@ -29,6 +29,57 @@
<object class="AdwWindowTitle"></object>
</property>
<property name="show-end-title-buttons" bind-source="Sidebar" bind-property="compact"
bind-flags="sync-create"/>
+ <child type="start">
+ <object class="GtkMenuButton" id="accounts_button">
+ <property name="icon-name">system-users-symbolic</property>
+ <property name="popover">
+ <object class="GtkPopover">
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkListView" id="account_switcher">
+ <property name="name">account-switcher</property>
+ <property name="factory">
+ <object class="GtkBuilderListItemFactory">
+ <property
name="resource">/org/gnome/FractalNext/sidebar-account-switcher-item.ui</property>
+ </object>
+ </property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkSeparator"></object>
+ </child>
+ <child>
+ <object class="GtkButton" id="new_login">
+ <property name="name">new-login</property>
+ <property name="action-name">app.new-login</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+ <property name="spacing">10</property>
+ <child>
+ <object class="AdwAvatar">
+ <property name="icon-name">list-add-symbolic</property>
+ <property name="size">40</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="label" translatable="yes">_Add account</property>
+ <property name="use-underline">true</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </property>
+ </object>
+ </child>
<child type="end">
<object class="GtkMenuButton" id="appmenu_button">
<property name="icon-name">open-menu-symbolic</property>
diff --git a/src/session/mod.rs b/src/session/mod.rs
index 311bb445..23bf48bc 100644
--- a/src/session/mod.rs
+++ b/src/session/mod.rs
@@ -26,7 +26,7 @@ use adw;
use adw::subclass::prelude::BinImpl;
use gtk::subclass::prelude::*;
use gtk::{self, prelude::*};
-use gtk::{gio, glib, glib::clone, glib::SyncSender, CompositeTemplate};
+use gtk::{gio, glib, glib::clone, glib::SyncSender, CompositeTemplate, SelectionModel};
use gtk_macros::send;
use log::error;
use matrix_sdk::ruma::{
@@ -450,4 +450,9 @@ impl Session {
fn handle_sync_response(&self, response: SyncResponse) {
self.room_list().handle_response_rooms(response.rooms);
}
+
+ pub fn set_logged_in_users(&self, sessions_stack_pages: &SelectionModel) {
+ let priv_ = &imp::Session::from_instance(self);
+ priv_.sidebar.set_logged_in_users(sessions_stack_pages);
+ }
}
diff --git a/src/session/sidebar/sidebar.rs b/src/session/sidebar/sidebar.rs
index 04eebb41..e9584a55 100644
--- a/src/session/sidebar/sidebar.rs
+++ b/src/session/sidebar/sidebar.rs
@@ -1,5 +1,5 @@
use adw::subclass::prelude::BinImpl;
-use gtk::{gio, glib, prelude::*, subclass::prelude::*, CompositeTemplate};
+use gtk::{gio, glib, prelude::*, subclass::prelude::*, CompositeTemplate, SelectionModel};
use crate::session::{
content::ContentType,
@@ -23,6 +23,8 @@ mod imp {
#[template_child]
pub headerbar: TemplateChild<adw::HeaderBar>,
#[template_child]
+ pub account_switcher: TemplateChild<gtk::ListView>,
+ #[template_child]
pub listview: TemplateChild<gtk::ListView>,
#[template_child]
pub room_search_entry: TemplateChild<gtk::SearchEntry>,
@@ -254,4 +256,10 @@ impl Sidebar {
priv_.selected_room.replace(selected_room);
self.notify("selected-room");
}
+
+ pub fn set_logged_in_users(&self, sessions_stack_pages: &SelectionModel) {
+ let account_switcher = imp::Sidebar::from_instance(self).account_switcher.get();
+
+ account_switcher.set_model(Some(sessions_stack_pages));
+ }
}
diff --git a/src/window.rs b/src/window.rs
index 7485a1d9..ca973c6c 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -107,6 +107,7 @@ impl Window {
fn add_session(&self, session: &Session) {
let priv_ = &imp::Window::from_instance(self);
+ session.set_logged_in_users(&priv_.sessions.pages());
priv_.sessions.add_child(session);
priv_.sessions.set_visible_child(session);
self.install_session_actions(session);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]