Browse Source

account-switcher: Replace the "user" and "entry" terms

Use "session" and "item" instead.

"User" is not exact as we allow the same user to log in several
sessions.
"Entry" is easily associated with GtkEntry and can be confusing.
merge-requests/1327/merge
Kévin Commaille 3 years ago
parent
commit
2c842bef47
No known key found for this signature in database
GPG Key ID: 29A48C1F03620416
  1. 3
      data/resources/resources.gresource.xml
  2. 10
      data/resources/ui/session-item-row.ui
  3. 3
      data/resources/ui/sidebar-account-switcher.ui
  4. 18
      src/account_switcher/mod.rs
  5. 36
      src/account_switcher/session_item.rs

3
data/resources/resources.gresource.xml

@ -136,6 +136,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="qr-code-scanner.ui">ui/qr-code-scanner.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="room-creation.ui">ui/room-creation.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="room-title.ui">ui/room-title.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="session-item-row.ui">ui/session-item-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="session-verification.ui">ui/session-verification.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="session.ui">ui/session.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts.ui">ui/shortcuts.ui</file>
@ -146,9 +147,7 @@
<file compressed="true" preprocess="xml-stripblanks" alias="sidebar-verification-row.ui">ui/sidebar-verification-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="sidebar.ui">ui/sidebar.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="spinner-button.ui">ui/spinner-button.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="user-entry-row.ui">ui/user-entry-row.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="verification-emoji.ui">ui/verification-emoji.ui</file>
<file compressed="true" preprocess="xml-stripblanks" alias="window.ui">ui/window.ui</file>
</gresource>
</gresources>

10
data/resources/ui/user-entry-row.ui → data/resources/ui/session-item-row.ui

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="UserEntryRow" parent="GtkListBoxRow">
<template class="SessionItemRow" parent="GtkListBoxRow">
<property name="selectable">false</property>
<style>
<class name="account-switcher-row"/>
@ -9,12 +9,12 @@
<object class="GtkBox">
<property name="spacing">10</property>
<child>
<object class="AvatarWithSelection" id="account_avatar">
<object class="AvatarWithSelection" id="avatar">
<property name="size">40</property>
<binding name="data">
<lookup name="avatar-data" type="User">
<lookup name="user" type="Session">
<lookup name="session">UserEntryRow</lookup>
<lookup name="session">SessionItemRow</lookup>
</lookup>
</lookup>
</binding>
@ -31,7 +31,7 @@
<binding name="label">
<lookup name="display-name" type="User">
<lookup name="user" type="Session">
<lookup name="session">UserEntryRow</lookup>
<lookup name="session">SessionItemRow</lookup>
</lookup>
</lookup>
</binding>
@ -44,7 +44,7 @@
<binding name="label">
<lookup name="user-id" type="User">
<lookup name="user" type="Session">
<lookup name="session">UserEntryRow</lookup>
<lookup name="session">SessionItemRow</lookup>
</lookup>
</lookup>
</binding>

3
data/resources/ui/sidebar-account-switcher.ui

@ -2,7 +2,7 @@
<interface>
<template class="AccountSwitcher" parent="GtkPopover">
<child>
<object class="GtkListBox" id="entries">
<object class="GtkListBox" id="sessions">
<property name="activate_on_single_click">true</property>
<child>
<object class="GtkListBoxRow">
@ -47,4 +47,3 @@
</style>
</template>
</interface>

18
src/account_switcher/mod.rs

@ -8,9 +8,9 @@ use gtk::{
use crate::session::Session;
mod avatar_with_selection;
mod user_entry;
mod session_item;
use user_entry::UserEntryRow;
use session_item::SessionItemRow;
mod imp {
use std::cell::RefCell;
@ -24,7 +24,7 @@ mod imp {
#[template(resource = "/org/gnome/Fractal/sidebar-account-switcher.ui")]
pub struct AccountSwitcher {
#[template_child]
pub entries: TemplateChild<gtk::ListBox>,
pub sessions: TemplateChild<gtk::ListBox>,
pub pages: RefCell<Option<gtk::SelectionModel>>,
pub pages_handler: RefCell<Option<glib::SignalHandlerId>>,
pub selection_handler: RefCell<Option<glib::SignalHandlerId>>,
@ -79,11 +79,11 @@ mod imp {
fn constructed(&self) {
self.parent_constructed();
self.entries.connect_row_activated(move |_, row| {
self.sessions.connect_row_activated(move |_, row| {
row.activate_action("account-switcher.close", None).unwrap();
if let Some(session) = row
.downcast_ref::<UserEntryRow>()
.downcast_ref::<SessionItemRow>()
.and_then(|row| row.session())
{
session
@ -159,14 +159,14 @@ impl AccountSwitcher {
}
fn update_rows(&self, model: &SelectionModel, position: u32, removed: u32, added: u32) {
let listbox = self.imp().entries.get();
let listbox = self.imp().sessions.get();
for _ in 0..removed {
if let Some(row) = listbox.row_at_index(position as i32) {
listbox.remove(&row);
}
}
for i in position..(position + added) {
let row = UserEntryRow::new(
let row = SessionItemRow::new(
&model
.item(i)
.unwrap()
@ -190,9 +190,9 @@ impl AccountSwitcher {
for i in position..(position + n_items) {
if let Some(row) = imp
.entries
.sessions
.row_at_index(i as i32)
.and_then(|row| row.downcast::<UserEntryRow>().ok())
.and_then(|row| row.downcast::<SessionItemRow>().ok())
{
row.set_selected(pages.is_selected(i));
}

36
src/account_switcher/user_entry.rs → src/account_switcher/session_item.rs

@ -11,21 +11,22 @@ mod imp {
use super::*;
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/Fractal/user-entry-row.ui")]
pub struct UserEntryRow {
#[template(resource = "/org/gnome/Fractal/session-item-row.ui")]
pub struct SessionItemRow {
#[template_child]
pub account_avatar: TemplateChild<AvatarWithSelection>,
pub avatar: TemplateChild<AvatarWithSelection>,
#[template_child]
pub display_name: TemplateChild<gtk::Label>,
#[template_child]
pub user_id: TemplateChild<gtk::Label>,
/// The session this item represents.
pub session: glib::WeakRef<Session>,
}
#[glib::object_subclass]
impl ObjectSubclass for UserEntryRow {
const NAME: &'static str = "UserEntryRow";
type Type = super::UserEntryRow;
impl ObjectSubclass for SessionItemRow {
const NAME: &'static str = "SessionItemRow";
type Type = super::SessionItemRow;
type ParentType = gtk::ListBoxRow;
fn class_init(klass: &mut Self::Class) {
@ -38,7 +39,7 @@ mod imp {
}
}
impl ObjectImpl for UserEntryRow {
impl ObjectImpl for SessionItemRow {
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
@ -75,18 +76,19 @@ mod imp {
}
}
impl WidgetImpl for UserEntryRow {}
impl BinImpl for UserEntryRow {}
impl ListBoxRowImpl for UserEntryRow {}
impl WidgetImpl for SessionItemRow {}
impl BinImpl for SessionItemRow {}
impl ListBoxRowImpl for SessionItemRow {}
}
glib::wrapper! {
pub struct UserEntryRow(ObjectSubclass<imp::UserEntryRow>)
/// A `GtkListBoxRow` representing a logged-in session.
pub struct SessionItemRow(ObjectSubclass<imp::SessionItemRow>)
@extends gtk::Widget, gtk::ListBoxRow, @implements gtk::Accessible;
}
#[gtk::template_callbacks]
impl UserEntryRow {
impl SessionItemRow {
pub fn new(session: &Session) -> Self {
glib::Object::builder().property("session", session).build()
}
@ -95,11 +97,11 @@ impl UserEntryRow {
pub fn set_selected(&self, selected: bool) {
let imp = self.imp();
if imp.account_avatar.is_selected() == selected {
if imp.avatar.is_selected() == selected {
return;
}
imp.account_avatar.set_selected(selected);
imp.avatar.set_selected(selected);
if selected {
imp.display_name.add_css_class("bold");
@ -112,7 +114,7 @@ impl UserEntryRow {
/// Whether this session is selected.
pub fn is_selected(&self) -> bool {
self.imp().account_avatar.is_selected()
self.imp().avatar.is_selected()
}
#[template_callback]
@ -128,12 +130,12 @@ impl UserEntryRow {
.unwrap();
}
/// The session this entry represents.
/// The session this item represents.
pub fn session(&self) -> Option<Session> {
self.imp().session.upgrade()
}
/// Set the session this entry represents.
/// Set the session this item represents.
pub fn set_session(&self, session: Option<&Session>) {
self.imp().session.set(session);
}
Loading…
Cancel
Save