Browse Source
Also check if the url provided is a valid homeserver. Closes #769merge-requests/1327/merge
10 changed files with 677 additions and 89 deletions
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<interface> |
||||
<template class="LoginAdvancedDialog" parent="AdwPreferencesWindow"> |
||||
<property name="modal">True</property> |
||||
<property name="title" translatable="yes">Homeserver Discovery</property> |
||||
<property name="destroy-with-parent">True</property> |
||||
<property name="default-width">500</property> |
||||
<property name="default-height">300</property> |
||||
<property name="search-enabled">false</property> |
||||
<child> |
||||
<object class="AdwPreferencesPage"> |
||||
<child> |
||||
<object class="AdwPreferencesGroup"> |
||||
<property name="description" translatable="yes">Auto-discovery, also known as "well-known lookup", allows to discover the URL of a Matrix homeserver from a domain name. This should only be disabled if your homeserver doesn’t support auto-discovery or if you want to provide the URL yourself.</property> |
||||
<child> |
||||
<object class="AdwActionRow"> |
||||
<property name="title" translatable="yes">_Auto-discovery</property> |
||||
<property name="use-underline">true</property> |
||||
<child> |
||||
<object class="GtkSwitch"> |
||||
<property name="valign">center</property> |
||||
<property name="active" bind-source="LoginAdvancedDialog" bind-property="autodiscovery" bind-flags="sync-create|bidirectional"/> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
</object> |
||||
</child> |
||||
</template> |
||||
</interface> |
||||
@ -0,0 +1,118 @@
|
||||
use std::cell::Cell; |
||||
|
||||
use adw::subclass::prelude::*; |
||||
use gtk::{gdk, glib, prelude::*, subclass::prelude::*, CompositeTemplate}; |
||||
|
||||
mod imp { |
||||
use glib::subclass::InitializingObject; |
||||
use once_cell::sync::Lazy; |
||||
|
||||
use super::*; |
||||
|
||||
#[derive(Debug, Default, CompositeTemplate)] |
||||
#[template(resource = "/org/gnome/FractalNext/login-advanced-dialog.ui")] |
||||
pub struct LoginAdvancedDialog { |
||||
pub autodiscovery: Cell<bool>, |
||||
} |
||||
|
||||
#[glib::object_subclass] |
||||
impl ObjectSubclass for LoginAdvancedDialog { |
||||
const NAME: &'static str = "LoginAdvancedDialog"; |
||||
type Type = super::LoginAdvancedDialog; |
||||
type ParentType = adw::PreferencesWindow; |
||||
|
||||
fn class_init(klass: &mut Self::Class) { |
||||
Self::bind_template(klass); |
||||
|
||||
klass.add_binding_signal( |
||||
gdk::Key::Escape, |
||||
gdk::ModifierType::empty(), |
||||
"close-request", |
||||
None, |
||||
); |
||||
} |
||||
|
||||
fn instance_init(obj: &InitializingObject<Self>) { |
||||
obj.init_template(); |
||||
} |
||||
} |
||||
|
||||
impl ObjectImpl for LoginAdvancedDialog { |
||||
fn properties() -> &'static [glib::ParamSpec] { |
||||
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| { |
||||
vec![glib::ParamSpecBoolean::new( |
||||
"autodiscovery", |
||||
"Auto-discovery", |
||||
"Whether auto-discovery is enabled", |
||||
true, |
||||
glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT, |
||||
)] |
||||
}); |
||||
|
||||
PROPERTIES.as_ref() |
||||
} |
||||
|
||||
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { |
||||
match pspec.name() { |
||||
"autodiscovery" => obj.autodiscovery().to_value(), |
||||
_ => unimplemented!(), |
||||
} |
||||
} |
||||
|
||||
fn set_property( |
||||
&self, |
||||
obj: &Self::Type, |
||||
_id: usize, |
||||
value: &glib::Value, |
||||
pspec: &glib::ParamSpec, |
||||
) { |
||||
match pspec.name() { |
||||
"autodiscovery" => obj.set_autodiscovery(value.get().unwrap()), |
||||
_ => unimplemented!(), |
||||
} |
||||
} |
||||
} |
||||
|
||||
impl WidgetImpl for LoginAdvancedDialog {} |
||||
impl WindowImpl for LoginAdvancedDialog {} |
||||
impl AdwWindowImpl for LoginAdvancedDialog {} |
||||
impl PreferencesWindowImpl for LoginAdvancedDialog {} |
||||
} |
||||
|
||||
glib::wrapper! { |
||||
pub struct LoginAdvancedDialog(ObjectSubclass<imp::LoginAdvancedDialog>) |
||||
@extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow, @implements gtk::Accessible; |
||||
} |
||||
|
||||
impl LoginAdvancedDialog { |
||||
pub fn new(window: >k::Window) -> Self { |
||||
glib::Object::new(&[("transient-for", window)]) |
||||
.expect("Failed to create LoginAdvancedDialog") |
||||
} |
||||
|
||||
pub fn autodiscovery(&self) -> bool { |
||||
self.imp().autodiscovery.get() |
||||
} |
||||
|
||||
pub fn set_autodiscovery(&self, autodiscovery: bool) { |
||||
let priv_ = self.imp(); |
||||
|
||||
priv_.autodiscovery.set(autodiscovery); |
||||
self.notify("autodiscovery"); |
||||
} |
||||
|
||||
pub async fn run_future(&self) { |
||||
let (sender, receiver) = futures::channel::oneshot::channel(); |
||||
let sender = Cell::new(Some(sender)); |
||||
|
||||
self.connect_close_request(move |_| { |
||||
if let Some(sender) = sender.take() { |
||||
sender.send(()).unwrap(); |
||||
} |
||||
gtk::Inhibit(false) |
||||
}); |
||||
|
||||
self.show(); |
||||
receiver.await.unwrap(); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue