diff --git a/data/resources/ui/preferences.blp b/data/resources/ui/preferences.blp index 160d058..2f1abd2 100644 --- a/data/resources/ui/preferences.blp +++ b/data/resources/ui/preferences.blp @@ -1,7 +1,7 @@ using Gtk 4.0; using Adw 1; -template $NotifyPreferences : Adw.PreferencesWindow { +template $NotifyPreferences : Adw.PreferencesDialog { width-request: 240; height-request: 360; Adw.PreferencesPage { diff --git a/src/application.rs b/src/application.rs index 9f0b341..49da89a 100644 --- a/src/application.rs +++ b/src/application.rs @@ -4,13 +4,13 @@ use std::path::PathBuf; use std::pin::Pin; use std::rc::Rc; +use adw::prelude::*; use adw::subclass::prelude::*; use capnp_rpc::{rpc_twoparty_capnp, twoparty, RpcSystem}; use futures::stream::Stream; use futures::AsyncReadExt; use gio::SocketClient; use gio::UnixSocketAddress; -use gtk::prelude::*; use gtk::{gdk, gio, glib}; use ntfy_daemon::models; use ntfy_daemon::ntfy_capnp::system_notifier; @@ -217,23 +217,20 @@ impl NotifyApplication { } fn show_about_dialog(&self) { - let dialog = adw::AboutWindow::from_appdata( + let dialog = adw::AboutDialog::from_appdata( "/com/ranfdev/Notify/com.ranfdev.Notify.metainfo.xml", None, ); if let Some(w) = self.imp().window.borrow().upgrade() { - dialog.set_transient_for(Some(&w)); + dialog.present(&w); } - - dialog.present(); } fn show_preferences(&self) { let win = crate::widgets::NotifyPreferences::new( self.main_window().imp().notifier.get().unwrap().clone(), ); - win.set_transient_for(Some(&self.main_window())); - win.present(); + win.present(&self.main_window()); } pub fn run(&self) -> glib::ExitCode { diff --git a/src/widgets/add_subscription_dialog.rs b/src/widgets/add_subscription_dialog.rs index d6c9f70..004b176 100644 --- a/src/widgets/add_subscription_dialog.rs +++ b/src/widgets/add_subscription_dialog.rs @@ -31,11 +31,6 @@ mod imp { type ParentType = adw::Dialog; fn class_init(klass: &mut Self::Class) { - klass.add_binding_action( - gtk::gdk::Key::Escape, - gtk::gdk::ModifierType::empty(), - "window.close", - ); klass.install_action("default.activate", None, |this, _, _| { this.emit_subscribe_request(); }); diff --git a/src/widgets/advanced_message_dialog.rs b/src/widgets/advanced_message_dialog.rs index 26a6bbc..d219dbd 100644 --- a/src/widgets/advanced_message_dialog.rs +++ b/src/widgets/advanced_message_dialog.rs @@ -20,30 +20,22 @@ mod imp { impl ObjectSubclass for AdvancedMessageDialog { const NAME: &'static str = "AdvancedMessageDialog"; type Type = super::AdvancedMessageDialog; - type ParentType = adw::Window; + type ParentType = adw::Dialog; } impl ObjectImpl for AdvancedMessageDialog {} impl WidgetImpl for AdvancedMessageDialog {} - impl WindowImpl for AdvancedMessageDialog {} - impl AdwWindowImpl for AdvancedMessageDialog {} + impl AdwDialogImpl for AdvancedMessageDialog {} } glib::wrapper! { pub struct AdvancedMessageDialog(ObjectSubclass) - @extends gtk::Widget, gtk::Window, adw::Window; + @extends gtk::Widget, adw::Dialog; } impl AdvancedMessageDialog { - pub fn new( - parent: &impl IsA, - subscription: Subscription, - message: String, - ) -> Self { + pub fn new(subscription: Subscription, message: String) -> Self { let this: Self = glib::Object::new(); - this.set_transient_for(Some(parent)); - this.set_modal(true); - this.set_default_height(400); this.imp().subscription.set(subscription).unwrap(); this.build_ui( this.imp().subscription.get().unwrap().topic().clone(), @@ -52,6 +44,9 @@ impl AdvancedMessageDialog { this } fn build_ui(&self, topic: String, message: String) { + self.set_title("Advanced Message"); + self.set_content_height(480); + self.set_content_width(480); let this = self.clone(); relm4_macros::view! { content = &adw::ToolbarView { @@ -59,7 +54,7 @@ impl AdvancedMessageDialog { #[wrap(Some)] set_content: toast_overlay = &adw::ToastOverlay { #[wrap(Some)] - set_child = &adw::Clamp { + set_child = >k::ScrolledWindow { #[wrap(Some)] set_child = >k::Box { set_margin_top: 8, @@ -82,22 +77,19 @@ impl AdvancedMessageDialog { set_xalign: 0.0, set_halign: gtk::Align::Start, }, - append = >k::ScrolledWindow { - #[wrap(Some)] - set_child: text_view = &gsv::View { - add_css_class: "code", - set_tab_width: 4, - set_indent_width: 2, - set_auto_indent: true, - set_top_margin: 4, - set_bottom_margin: 4, - set_left_margin: 4, - set_right_margin: 4, - set_hexpand: true, - set_vexpand: true, - set_monospace: true, - set_background_pattern: gsv::BackgroundPatternType::Grid - }, + append: text_view = &gsv::View { + add_css_class: "code", + set_tab_width: 4, + set_indent_width: 2, + set_auto_indent: true, + set_top_margin: 4, + set_bottom_margin: 4, + set_left_margin: 4, + set_right_margin: 4, + set_hexpand: true, + set_vexpand: true, + set_monospace: true, + set_background_pattern: gsv::BackgroundPatternType::Grid }, append = >k::Label { add_css_class: "heading", @@ -166,9 +158,9 @@ impl AdvancedMessageDialog { add_css_class: "circular", add_css_class: "small", set_label: "?", - connect_clicked[this] => move |_| { + connect_clicked => move |_| { gtk::UriLauncher::new("https://docs.ntfy.sh/publish/#publish-as-json").launch( - Some(&this), + None::<>k::Window>, gio::Cancellable::NONE, |_| {} ); @@ -221,6 +213,6 @@ impl AdvancedMessageDialog { }; let scheme = gsv::StyleSchemeManager::default().scheme(scheme_name); buffer.set_style_scheme(scheme.as_ref()); - this.set_content(Some(&content)); + this.set_child(Some(&content)); } } diff --git a/src/widgets/preferences.rs b/src/widgets/preferences.rs index 2ed3a34..2cd9540 100644 --- a/src/widgets/preferences.rs +++ b/src/widgets/preferences.rs @@ -48,7 +48,7 @@ mod imp { impl ObjectSubclass for NotifyPreferences { const NAME: &'static str = "NotifyPreferences"; type Type = super::NotifyPreferences; - type ParentType = adw::PreferencesWindow; + type ParentType = adw::PreferencesDialog; fn class_init(klass: &mut Self::Class) { klass.bind_template(); @@ -66,16 +66,13 @@ mod imp { } impl WidgetImpl for NotifyPreferences {} - impl WindowImpl for NotifyPreferences {} - - impl ApplicationWindowImpl for NotifyPreferences {} - impl AdwWindowImpl for NotifyPreferences {} - impl PreferencesWindowImpl for NotifyPreferences {} + impl AdwDialogImpl for NotifyPreferences {} + impl PreferencesDialogImpl for NotifyPreferences {} } glib::wrapper! { pub struct NotifyPreferences(ObjectSubclass) - @extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow, + @extends gtk::Widget, adw::Dialog, adw::PreferencesDialog, @implements gio::ActionMap, gio::ActionGroup, gtk::Root; } diff --git a/src/widgets/subscription_info_dialog.rs b/src/widgets/subscription_info_dialog.rs index 4ab03e5..ca0de5e 100644 --- a/src/widgets/subscription_info_dialog.rs +++ b/src/widgets/subscription_info_dialog.rs @@ -30,11 +30,6 @@ mod imp { fn class_init(klass: &mut Self::Class) { klass.bind_template(); - klass.add_binding_action( - gtk::gdk::Key::Escape, - gtk::gdk::ModifierType::empty(), - "window.close", - ); } // You must call `Widget`'s `init_template()` within `instance_init()`. diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 3adc700..c233608 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -236,8 +236,7 @@ impl NotifyWindow { imp.code_btn.connect_clicked(move |_| { let this = this.clone(); this.selected_subscription().map(move |sub| { - AdvancedMessageDialog::new(&this, sub, this.imp().entry.text().to_string()) - .present() + AdvancedMessageDialog::new(sub, this.imp().entry.text().to_string()).present(&this) }); }); }