Skip to content

Commit 86d1472

Browse files
committed
finish port to libadwaita dialogs
1 parent 29377dc commit 86d1472

File tree

7 files changed

+34
-59
lines changed

7 files changed

+34
-59
lines changed

data/resources/ui/preferences.blp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Gtk 4.0;
22
using Adw 1;
33

4-
template $NotifyPreferences : Adw.PreferencesWindow {
4+
template $NotifyPreferences : Adw.PreferencesDialog {
55
width-request: 240;
66
height-request: 360;
77
Adw.PreferencesPage {

src/application.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use std::path::PathBuf;
44
use std::pin::Pin;
55
use std::rc::Rc;
66

7+
use adw::prelude::*;
78
use adw::subclass::prelude::*;
89
use capnp_rpc::{rpc_twoparty_capnp, twoparty, RpcSystem};
910
use futures::stream::Stream;
1011
use futures::AsyncReadExt;
1112
use gio::SocketClient;
1213
use gio::UnixSocketAddress;
13-
use gtk::prelude::*;
1414
use gtk::{gdk, gio, glib};
1515
use ntfy_daemon::models;
1616
use ntfy_daemon::ntfy_capnp::system_notifier;
@@ -217,23 +217,20 @@ impl NotifyApplication {
217217
}
218218

219219
fn show_about_dialog(&self) {
220-
let dialog = adw::AboutWindow::from_appdata(
220+
let dialog = adw::AboutDialog::from_appdata(
221221
"/com/ranfdev/Notify/com.ranfdev.Notify.metainfo.xml",
222222
None,
223223
);
224224
if let Some(w) = self.imp().window.borrow().upgrade() {
225-
dialog.set_transient_for(Some(&w));
225+
dialog.present(&w);
226226
}
227-
228-
dialog.present();
229227
}
230228

231229
fn show_preferences(&self) {
232230
let win = crate::widgets::NotifyPreferences::new(
233231
self.main_window().imp().notifier.get().unwrap().clone(),
234232
);
235-
win.set_transient_for(Some(&self.main_window()));
236-
win.present();
233+
win.present(&self.main_window());
237234
}
238235

239236
pub fn run(&self) -> glib::ExitCode {

src/widgets/add_subscription_dialog.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ mod imp {
3131
type ParentType = adw::Dialog;
3232

3333
fn class_init(klass: &mut Self::Class) {
34-
klass.add_binding_action(
35-
gtk::gdk::Key::Escape,
36-
gtk::gdk::ModifierType::empty(),
37-
"window.close",
38-
);
3934
klass.install_action("default.activate", None, |this, _, _| {
4035
this.emit_subscribe_request();
4136
});

src/widgets/advanced_message_dialog.rs

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,22 @@ mod imp {
2020
impl ObjectSubclass for AdvancedMessageDialog {
2121
const NAME: &'static str = "AdvancedMessageDialog";
2222
type Type = super::AdvancedMessageDialog;
23-
type ParentType = adw::Window;
23+
type ParentType = adw::Dialog;
2424
}
2525

2626
impl ObjectImpl for AdvancedMessageDialog {}
2727
impl WidgetImpl for AdvancedMessageDialog {}
28-
impl WindowImpl for AdvancedMessageDialog {}
29-
impl AdwWindowImpl for AdvancedMessageDialog {}
28+
impl AdwDialogImpl for AdvancedMessageDialog {}
3029
}
3130

3231
glib::wrapper! {
3332
pub struct AdvancedMessageDialog(ObjectSubclass<imp::AdvancedMessageDialog>)
34-
@extends gtk::Widget, gtk::Window, adw::Window;
33+
@extends gtk::Widget, adw::Dialog;
3534
}
3635

3736
impl AdvancedMessageDialog {
38-
pub fn new(
39-
parent: &impl IsA<gtk::Window>,
40-
subscription: Subscription,
41-
message: String,
42-
) -> Self {
37+
pub fn new(subscription: Subscription, message: String) -> Self {
4338
let this: Self = glib::Object::new();
44-
this.set_transient_for(Some(parent));
45-
this.set_modal(true);
46-
this.set_default_height(400);
4739
this.imp().subscription.set(subscription).unwrap();
4840
this.build_ui(
4941
this.imp().subscription.get().unwrap().topic().clone(),
@@ -52,14 +44,17 @@ impl AdvancedMessageDialog {
5244
this
5345
}
5446
fn build_ui(&self, topic: String, message: String) {
47+
self.set_title("Advanced Message");
48+
self.set_content_height(480);
49+
self.set_content_width(480);
5550
let this = self.clone();
5651
relm4_macros::view! {
5752
content = &adw::ToolbarView {
5853
add_top_bar = &adw::HeaderBar {},
5954
#[wrap(Some)]
6055
set_content: toast_overlay = &adw::ToastOverlay {
6156
#[wrap(Some)]
62-
set_child = &adw::Clamp {
57+
set_child = &gtk::ScrolledWindow {
6358
#[wrap(Some)]
6459
set_child = &gtk::Box {
6560
set_margin_top: 8,
@@ -82,22 +77,19 @@ impl AdvancedMessageDialog {
8277
set_xalign: 0.0,
8378
set_halign: gtk::Align::Start,
8479
},
85-
append = &gtk::ScrolledWindow {
86-
#[wrap(Some)]
87-
set_child: text_view = &gsv::View {
88-
add_css_class: "code",
89-
set_tab_width: 4,
90-
set_indent_width: 2,
91-
set_auto_indent: true,
92-
set_top_margin: 4,
93-
set_bottom_margin: 4,
94-
set_left_margin: 4,
95-
set_right_margin: 4,
96-
set_hexpand: true,
97-
set_vexpand: true,
98-
set_monospace: true,
99-
set_background_pattern: gsv::BackgroundPatternType::Grid
100-
},
80+
append: text_view = &gsv::View {
81+
add_css_class: "code",
82+
set_tab_width: 4,
83+
set_indent_width: 2,
84+
set_auto_indent: true,
85+
set_top_margin: 4,
86+
set_bottom_margin: 4,
87+
set_left_margin: 4,
88+
set_right_margin: 4,
89+
set_hexpand: true,
90+
set_vexpand: true,
91+
set_monospace: true,
92+
set_background_pattern: gsv::BackgroundPatternType::Grid
10193
},
10294
append = &gtk::Label {
10395
add_css_class: "heading",
@@ -166,9 +158,9 @@ impl AdvancedMessageDialog {
166158
add_css_class: "circular",
167159
add_css_class: "small",
168160
set_label: "?",
169-
connect_clicked[this] => move |_| {
161+
connect_clicked => move |_| {
170162
gtk::UriLauncher::new("https://docs.ntfy.sh/publish/#publish-as-json").launch(
171-
Some(&this),
163+
None::<&gtk::Window>,
172164
gio::Cancellable::NONE,
173165
|_| {}
174166
);
@@ -221,6 +213,6 @@ impl AdvancedMessageDialog {
221213
};
222214
let scheme = gsv::StyleSchemeManager::default().scheme(scheme_name);
223215
buffer.set_style_scheme(scheme.as_ref());
224-
this.set_content(Some(&content));
216+
this.set_child(Some(&content));
225217
}
226218
}

src/widgets/preferences.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ mod imp {
4848
impl ObjectSubclass for NotifyPreferences {
4949
const NAME: &'static str = "NotifyPreferences";
5050
type Type = super::NotifyPreferences;
51-
type ParentType = adw::PreferencesWindow;
51+
type ParentType = adw::PreferencesDialog;
5252

5353
fn class_init(klass: &mut Self::Class) {
5454
klass.bind_template();
@@ -66,16 +66,13 @@ mod imp {
6666
}
6767

6868
impl WidgetImpl for NotifyPreferences {}
69-
impl WindowImpl for NotifyPreferences {}
70-
71-
impl ApplicationWindowImpl for NotifyPreferences {}
72-
impl AdwWindowImpl for NotifyPreferences {}
73-
impl PreferencesWindowImpl for NotifyPreferences {}
69+
impl AdwDialogImpl for NotifyPreferences {}
70+
impl PreferencesDialogImpl for NotifyPreferences {}
7471
}
7572

7673
glib::wrapper! {
7774
pub struct NotifyPreferences(ObjectSubclass<imp::NotifyPreferences>)
78-
@extends gtk::Widget, gtk::Window, adw::Window, adw::PreferencesWindow,
75+
@extends gtk::Widget, adw::Dialog, adw::PreferencesDialog,
7976
@implements gio::ActionMap, gio::ActionGroup, gtk::Root;
8077
}
8178

src/widgets/subscription_info_dialog.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ mod imp {
3030

3131
fn class_init(klass: &mut Self::Class) {
3232
klass.bind_template();
33-
klass.add_binding_action(
34-
gtk::gdk::Key::Escape,
35-
gtk::gdk::ModifierType::empty(),
36-
"window.close",
37-
);
3833
}
3934

4035
// You must call `Widget`'s `init_template()` within `instance_init()`.

src/widgets/window.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ impl NotifyWindow {
236236
imp.code_btn.connect_clicked(move |_| {
237237
let this = this.clone();
238238
this.selected_subscription().map(move |sub| {
239-
AdvancedMessageDialog::new(&this, sub, this.imp().entry.text().to_string())
240-
.present()
239+
AdvancedMessageDialog::new(sub, this.imp().entry.text().to_string()).present(&this)
241240
});
242241
});
243242
}

0 commit comments

Comments
 (0)