room-creation: Use ToastableWindow

This commit is contained in:
Kévin Commaille 2023-11-17 13:04:29 +01:00
parent 04080ab740
commit 6bf5280f42
No known key found for this signature in database
GPG key ID: 29A48C1F03620416
2 changed files with 177 additions and 180 deletions

View file

@ -15,7 +15,10 @@ use ruma::events::{room::encryption::RoomEncryptionEventContent, InitialStateEve
use tracing::error;
use crate::{
components::SpinnerButton, prelude::*, session::model::Session, spawn, spawn_tokio, Window,
components::{SpinnerButton, ToastableWindow},
prelude::*,
session::model::Session,
spawn, spawn_tokio, toast, Window,
};
// MAX length of room addresses
@ -31,8 +34,6 @@ mod imp {
pub struct RoomCreation {
pub session: WeakRef<Session>,
#[template_child]
pub toast_overlay: TemplateChild<adw::ToastOverlay>,
#[template_child]
pub create_button: TemplateChild<SpinnerButton>,
#[template_child]
pub content: TemplateChild<gtk::Box>,
@ -58,7 +59,7 @@ mod imp {
impl ObjectSubclass for RoomCreation {
const NAME: &'static str = "RoomCreation";
type Type = super::RoomCreation;
type ParentType = adw::Window;
type ParentType = ToastableWindow;
fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass);
@ -110,12 +111,13 @@ mod imp {
impl WidgetImpl for RoomCreation {}
impl WindowImpl for RoomCreation {}
impl AdwWindowImpl for RoomCreation {}
impl ToastableWindowImpl for RoomCreation {}
}
glib::wrapper! {
/// Preference Window to display and update room details.
pub struct RoomCreation(ObjectSubclass<imp::RoomCreation>)
@extends gtk::Widget, gtk::Window, adw::Window, @implements gtk::Accessible;
@extends gtk::Widget, gtk::Window, adw::Window, ToastableWindow, @implements gtk::Accessible;
}
#[gtk::template_callbacks]
@ -236,8 +238,7 @@ impl RoomCreation {
}
}
imp.toast_overlay
.add_toast(adw::Toast::new(&error.to_user_facing()));
toast!(self, error.to_user_facing());
}
/// Check whether a room can be created with the current input.

View file

@ -1,178 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="RoomCreation" parent="AdwWindow">
<template class="RoomCreation" parent="ToastableWindow">
<property name="default-widget">create_button</property>
<property name="modal">True</property>
<property name="default-width">380</property>
<property name="default-height">620</property>
<property name="content">
<object class="AdwToastOverlay" id="toast_overlay">
<child>
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<property name="show-title">False</property>
</object>
</child>
<property name="content">
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="hscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property>
<property name="vexpand">True</property>
<property name="child-content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar">
<property name="show-title">False</property>
</object>
</child>
<property name="content">
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="hscrollbar-policy">never</property>
<property name="propagate-natural-height">True</property>
<property name="vexpand">True</property>
<property name="child">
<object class="AdwClamp">
<property name="maximum-size">444</property>
<property name="child">
<object class="AdwClamp">
<property name="maximum-size">444</property>
<property name="child">
<object class="GtkBox">
<object class="GtkBox">
<property name="orientation">vertical</property>
<property name="spacing">24</property>
<property name="margin-bottom">24</property>
<property name="margin-start">24</property>
<property name="margin-end">24</property>
<child type="top">
<object class="GtkLabel" id="heading">
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="max-width-chars">20</property>
<property name="justify">center</property>
<property name="xalign">0.5</property>
<property name="label" translatable="yes">New Room</property>
<style>
<class name="title-2"/>
</style>
</object>
</child>
<child>
<object class="GtkBox" id="content">
<property name="orientation">vertical</property>
<property name="spacing">24</property>
<property name="margin-bottom">24</property>
<property name="margin-start">24</property>
<property name="margin-end">24</property>
<child type="top">
<object class="GtkLabel" id="heading">
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="max-width-chars">20</property>
<property name="justify">center</property>
<property name="xalign">0.5</property>
<property name="label" translatable="yes">New Room</property>
<property name="spacing">18</property>
<child>
<object class="AdwPreferencesGroup">
<style>
<class name="title-2"/>
<class name="boxed-list"/>
</style>
<child>
<object class="AdwEntryRow" id="room_name">
<property name="title" translatable="yes">Name</property>
<signal name="changed" handler="validate_form" swapped="yes"/>
<signal name="entry-activated" handler="create_room" swapped="yes"/>
</object>
</child>
<child>
<object class="AdwEntryRow" id="room_topic">
<property name="title" translatable="yes">Topic (Optional)</property>
<signal name="entry-activated" handler="create_room" swapped="yes"/>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="content">
<property name="orientation">vertical</property>
<property name="spacing">18</property>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Room Visibility</property>
<child>
<object class="AdwPreferencesGroup">
<style>
<class name="boxed-list"/>
</style>
<child>
<object class="AdwEntryRow" id="room_name">
<property name="title" translatable="yes">Name</property>
<signal name="changed" handler="validate_form" swapped="yes"/>
<signal name="entry-activated" handler="create_room" swapped="yes"/>
</object>
</child>
<child>
<object class="AdwEntryRow" id="room_topic">
<property name="title" translatable="yes">Topic (Optional)</property>
<signal name="entry-activated" handler="create_room" swapped="yes"/>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="title" translatable="yes">Room Visibility</property>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Private</property>
<property name="subtitle" translatable="yes">Only invited people can join this room</property>
<property name="activatable_widget">visibility_private</property>
<child type="prefix">
<object class="GtkCheckButton" id="visibility_private">
<property name="valign">center</property>
<property name="active">True</property>
<signal name="toggled" handler="validate_form" swapped="yes"/>
</object>
</child>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Public</property>
<property name="subtitle" translatable="yes">Anyone can find and join this room</property>
<property name="activatable_widget">visibility_public</property>
<child type="prefix">
<object class="GtkCheckButton" id="visibility_public">
<property name="valign">center</property>
<property name="group">visibility_private</property>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="visible" bind-source="visibility_private" bind-property="active" bind-flags="sync-create"/>
<property name="margin-top">12</property>
<child>
<object class="AdwSwitchRow" id="encryption">
<property name="title" translatable="yes">End-to-End Encryption</property>
<property name="subtitle" translatable="yes">Cannot be disabled later</property>
</object>
</child>
<child>
<object class="GtkRevealer">
<property name="reveal-child" bind-source="encryption" bind-property="active" bind-flags="sync-create"/>
<property name="child">
<object class="GtkLabel">
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
<property name="margin-top">6</property>
<property name="label" translatable="yes">Fractal does not support online backup for encryption keys yet, so you will need to back them up manually or your message history will be lost if you lose access to all your sessions.</property>
<style>
<class name="warning"/>
<class name="caption"/>
</style>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="visible" bind-source="visibility_public" bind-property="active" bind-flags="sync-create"/>
<property name="title" translatable="yes">Room Address</property>
<child>
<object class="GtkBox">
<object class="AdwActionRow">
<property name="title" translatable="yes">Private</property>
<property name="subtitle" translatable="yes">Only invited people can join this room</property>
<property name="activatable_widget">visibility_private</property>
<child type="prefix">
<object class="GtkCheckButton" id="visibility_private">
<property name="valign">center</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="label">#</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="room_address">
<property name="valign">center</property>
<property name="max-width-chars">20</property>
<signal name="changed" handler="validate_form" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkLabel" id="server_name">
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<property name="active">True</property>
<signal name="toggled" handler="validate_form" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkRevealer" id="room_address_error_revealer">
<property name="child">
<object class="GtkLabel" id="room_address_error">
<style>
<class name="error"/>
<class name="caption"/>
</style>
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
</object>
</property>
</object>
</child>
<child>
<object class="AdwActionRow">
<property name="title" translatable="yes">Public</property>
<property name="subtitle" translatable="yes">Anyone can find and join this room</property>
<property name="activatable_widget">visibility_public</property>
<child type="prefix">
<object class="GtkCheckButton" id="visibility_public">
<property name="valign">center</property>
<property name="group">visibility_private</property>
</object>
</child>
</object>
@ -180,29 +97,108 @@
</object>
</child>
<child>
<object class="SpinnerButton" id="create_button">
<property name="label" translatable="yes">_Create Room</property>
<property name="use_underline">True</property>
<property name="sensitive">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="vexpand">true</property>
<signal name="clicked" handler="create_room" swapped="yes"/>
<style>
<class name="suggested-action"/>
<class name="standalone-button"/>
<class name="pill"/>
</style>
<object class="AdwPreferencesGroup">
<property name="visible" bind-source="visibility_private" bind-property="active" bind-flags="sync-create"/>
<property name="margin-top">12</property>
<child>
<object class="AdwSwitchRow" id="encryption">
<property name="title" translatable="yes">End-to-End Encryption</property>
<property name="subtitle" translatable="yes">Cannot be disabled later</property>
</object>
</child>
<child>
<object class="GtkRevealer">
<property name="reveal-child" bind-source="encryption" bind-property="active" bind-flags="sync-create"/>
<property name="child">
<object class="GtkLabel">
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
<property name="margin-top">6</property>
<property name="label" translatable="yes">Fractal does not support online backup for encryption keys yet, so you will need to back them up manually or your message history will be lost if you lose access to all your sessions.</property>
<style>
<class name="warning"/>
<class name="caption"/>
</style>
</object>
</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup">
<property name="visible" bind-source="visibility_public" bind-property="active" bind-flags="sync-create"/>
<property name="title" translatable="yes">Room Address</property>
<child>
<object class="GtkBox">
<property name="valign">center</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel">
<property name="label">#</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkEntry" id="room_address">
<property name="valign">center</property>
<property name="max-width-chars">20</property>
<signal name="changed" handler="validate_form" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkLabel" id="server_name">
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkRevealer" id="room_address_error_revealer">
<property name="child">
<object class="GtkLabel" id="room_address_error">
<style>
<class name="error"/>
<class name="caption"/>
</style>
<property name="wrap">True</property>
<property name="wrap-mode">word-char</property>
<property name="xalign">0.0</property>
</object>
</property>
</object>
</child>
</object>
</child>
</object>
</property>
</child>
<child>
<object class="SpinnerButton" id="create_button">
<property name="label" translatable="yes">_Create Room</property>
<property name="use_underline">True</property>
<property name="sensitive">False</property>
<property name="halign">center</property>
<property name="valign">end</property>
<property name="vexpand">true</property>
<signal name="clicked" handler="create_room" swapped="yes"/>
<style>
<class name="suggested-action"/>
<class name="standalone-button"/>
<class name="pill"/>
</style>
</object>
</child>
</object>
</property>
</object>
</property>
</object>
</child>
</property>
</object>
</property>
</template>