@@ -3,11 +3,11 @@ use std::cell::RefCell;
33
44use adw:: prelude:: * ;
55use adw:: subclass:: prelude:: * ;
6- use glib:: once_cell:: sync:: Lazy ;
76use glib:: subclass:: Signal ;
87use gtk:: gio;
98use gtk:: glib;
109use ntfy_daemon:: models;
10+ use once_cell:: sync:: Lazy ;
1111
1212#[ derive( Default , Debug , Clone ) ]
1313pub struct Widgets {
@@ -28,14 +28,13 @@ mod imp {
2828 impl ObjectSubclass for AddSubscriptionDialog {
2929 const NAME : & ' static str = "AddSubscriptionDialog" ;
3030 type Type = super :: AddSubscriptionDialog ;
31- type ParentType = adw:: Window ;
31+ type ParentType = adw:: Dialog ;
3232
3333 fn class_init ( klass : & mut Self :: Class ) {
3434 klass. add_binding_action (
3535 gtk:: gdk:: Key :: Escape ,
3636 gtk:: gdk:: ModifierType :: empty ( ) ,
3737 "window.close" ,
38- None ,
3938 ) ;
4039 klass. install_action ( "default.activate" , None , |this, _, _| {
4140 this. emit_subscribe_request ( ) ;
@@ -51,13 +50,12 @@ mod imp {
5150 }
5251 }
5352 impl WidgetImpl for AddSubscriptionDialog { }
54- impl WindowImpl for AddSubscriptionDialog { }
55- impl AdwWindowImpl for AddSubscriptionDialog { }
53+ impl AdwDialogImpl for AddSubscriptionDialog { }
5654}
5755
5856glib:: wrapper! {
5957 pub struct AddSubscriptionDialog ( ObjectSubclass <imp:: AddSubscriptionDialog >)
60- @extends gtk:: Widget , gtk :: Window , adw:: Window ,
58+ @extends gtk:: Widget , adw:: Dialog ,
6159 @implements gio:: ActionMap , gio:: ActionGroup , gtk:: Root ;
6260}
6361
@@ -75,72 +73,67 @@ impl AddSubscriptionDialog {
7573 fn build_ui ( & self ) {
7674 let imp = self . imp ( ) ;
7775 let obj = self . clone ( ) ;
78- obj. set_title ( Some ( "Subscribe To Topic" ) ) ;
79- obj. set_modal ( true ) ;
80- obj. set_default_width ( 360 ) ;
76+ obj. set_title ( "Subscribe To Topic" ) ;
8177
8278 relm4_macros:: view! {
8379 toolbar_view = adw:: ToolbarView {
8480 add_top_bar: & adw:: HeaderBar :: new( ) ,
8581 #[ wrap( Some ) ]
86- set_content = & adw:: Clamp {
87- #[ wrap( Some ) ]
88- set_child = & gtk:: Box {
89- set_orientation: gtk:: Orientation :: Vertical ,
90- set_spacing: 12 ,
91- set_margin_end: 12 ,
92- set_margin_start: 12 ,
93- set_margin_top: 12 ,
94- set_margin_bottom: 12 ,
95- append = & gtk:: Label {
96- add_css_class: "dim-label" ,
97- set_label: "Topics may not be password-protected, so choose a name that's not easy to guess. \
98- Once subscribed, you can PUT/POST notifications.",
99- set_wrap: true ,
100- set_xalign: 0.0 ,
101- set_wrap_mode: gtk:: pango:: WrapMode :: WordChar
102- } ,
103- append = & gtk:: ListBox {
104- add_css_class: "boxed-list" ,
105- append: topic_entry = & adw:: EntryRow {
106- set_title: "Topic" ,
107- set_activates_default: true ,
108- add_suffix = & gtk:: Button {
109- set_icon_name: "dice3-symbolic" ,
110- set_tooltip_text: Some ( "Generate name" ) ,
111- set_valign: gtk:: Align :: Center ,
112- add_css_class: "flat" ,
113- connect_clicked[ topic_entry] => move |_| {
114- use rand:: distributions:: Alphanumeric ;
115- use rand:: { thread_rng, Rng } ;
116- let mut rng = thread_rng( ) ;
117- let chars: String = ( 0 ..10 ) . map( |_| rng. sample( Alphanumeric ) as char ) . collect( ) ;
118- topic_entry. set_text( & chars) ;
119- }
120- }
121- } ,
122- append: server_expander = & adw:: ExpanderRow {
123- set_title: "Custom server..." ,
124- set_enable_expansion: imp. init_custom_server. get( ) . is_some( ) ,
125- set_expanded: imp. init_custom_server. get( ) . is_some( ) ,
126- set_show_enable_switch: true ,
127- add_row: server_entry = & adw:: EntryRow {
128- set_title: "Server" ,
129- set_text: imp. init_custom_server. get( ) . map( |x| x. as_str( ) ) . unwrap_or( "" ) ,
82+ set_content = & gtk:: Box {
83+ set_orientation: gtk:: Orientation :: Vertical ,
84+ set_spacing: 12 ,
85+ set_margin_end: 12 ,
86+ set_margin_start: 12 ,
87+ set_margin_top: 12 ,
88+ set_margin_bottom: 12 ,
89+ append = & gtk:: Label {
90+ add_css_class: "dim-label" ,
91+ set_label: "Topics may not be password-protected, so choose a name that's not easy to guess. \
92+ Once subscribed, you can PUT/POST notifications.",
93+ set_wrap: true ,
94+ set_xalign: 0.0 ,
95+ set_wrap_mode: gtk:: pango:: WrapMode :: WordChar
96+ } ,
97+ append = & gtk:: ListBox {
98+ add_css_class: "boxed-list" ,
99+ append: topic_entry = & adw:: EntryRow {
100+ set_title: "Topic" ,
101+ set_activates_default: true ,
102+ add_suffix = & gtk:: Button {
103+ set_icon_name: "dice3-symbolic" ,
104+ set_tooltip_text: Some ( "Generate name" ) ,
105+ set_valign: gtk:: Align :: Center ,
106+ add_css_class: "flat" ,
107+ connect_clicked[ topic_entry] => move |_| {
108+ use rand:: distributions:: Alphanumeric ;
109+ use rand:: { thread_rng, Rng } ;
110+ let mut rng = thread_rng( ) ;
111+ let chars: String = ( 0 ..10 ) . map( |_| rng. sample( Alphanumeric ) as char ) . collect( ) ;
112+ topic_entry. set_text( & chars) ;
130113 }
131114 }
132115 } ,
133- append: sub_btn = & gtk :: Button {
134- set_label : "Subscribe " ,
135- add_css_class : "suggested-action" ,
136- add_css_class : "pill" ,
137- set_halign : gtk :: Align :: Center ,
138- set_sensitive : false ,
139- connect_clicked [ obj ] => move |_| {
140- obj . emit_subscribe_request ( ) ;
116+ append: server_expander = & adw :: ExpanderRow {
117+ set_title : "Custom server... " ,
118+ set_enable_expansion : imp . init_custom_server . get ( ) . is_some ( ) ,
119+ set_expanded : imp . init_custom_server . get ( ) . is_some ( ) ,
120+ set_show_enable_switch : true ,
121+ add_row : server_entry = & adw :: EntryRow {
122+ set_title : "Server" ,
123+ set_text : imp . init_custom_server . get ( ) . map ( |x| x . as_str ( ) ) . unwrap_or ( "" ) ,
141124 }
142125 }
143126 } ,
127+ append: sub_btn = & gtk:: Button {
128+ set_label: "Subscribe" ,
129+ add_css_class: "suggested-action" ,
130+ add_css_class: "pill" ,
131+ set_halign: gtk:: Align :: Center ,
132+ set_sensitive: false ,
133+ connect_clicked[ obj] => move |_| {
134+ obj. emit_subscribe_request( ) ;
135+ }
136+ }
144137 } ,
145138 } ,
146139 }
@@ -175,7 +168,8 @@ impl AddSubscriptionDialog {
175168 sub_btn,
176169 } ) ;
177170
178- obj. set_content ( Some ( & toolbar_view) ) ;
171+ obj. set_content_width ( 480 ) ;
172+ obj. set_child ( Some ( & toolbar_view) ) ;
179173 }
180174 pub fn subscription ( & self ) -> Result < models:: Subscription , Vec < ntfy_daemon:: Error > > {
181175 let w = { self . imp ( ) . widgets . borrow ( ) . clone ( ) } ;
0 commit comments