From 7e7dcedaf31ee35499875491c9f569c575d28435 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 14 Feb 2022 14:55:59 +0100 Subject: Port from GTK3 to GTK4 --- .../ui/add_conversation/add_conference_dialog.vala | 71 +++++++++++----------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'main/src/ui/add_conversation/add_conference_dialog.vala') diff --git a/main/src/ui/add_conversation/add_conference_dialog.vala b/main/src/ui/add_conversation/add_conference_dialog.vala index a03f3db6..e078bc62 100644 --- a/main/src/ui/add_conversation/add_conference_dialog.vala +++ b/main/src/ui/add_conversation/add_conference_dialog.vala @@ -10,14 +10,13 @@ namespace Dino.Ui { public class AddConferenceDialog : Gtk.Dialog { private Stack stack = new Stack(); - private Button cancel_button; + private Button cancel_button = new Button() { visible=true }; private Button ok_button; - private Label cancel_label = new Label(_("Cancel")) {visible=true}; - private Image cancel_image = new Image.from_icon_name("go-previous-symbolic", IconSize.MENU) {visible=true}; private SelectJidFragment select_fragment; private ConferenceDetailsFragment details_fragment; private ConferenceList conference_list; + private ListBox conference_list_box; private StreamInteractor stream_interactor; @@ -29,7 +28,7 @@ public class AddConferenceDialog : Gtk.Dialog { stack.visible = true; stack.vhomogeneous = false; - get_content_area().add(stack); + get_content_area().append(stack); setup_headerbar(); setup_jid_add_view(); @@ -40,8 +39,7 @@ public class AddConferenceDialog : Gtk.Dialog { private void show_jid_add_view() { // Rewire headerbar (if CSD) if (Util.use_csd()) { - if (cancel_image.get_parent() != null) cancel_button.remove(cancel_image); - cancel_button.add(cancel_label); + cancel_button.set_label(_("Cancel")); cancel_button.clicked.disconnect(show_jid_add_view); cancel_button.clicked.connect(on_cancel); ok_button.label = _("Next"); @@ -59,8 +57,7 @@ public class AddConferenceDialog : Gtk.Dialog { private void show_conference_details_view() { // Rewire headerbar (if CSD) if (Util.use_csd()) { - if (cancel_label.get_parent() != null) cancel_button.remove(cancel_label); - cancel_button.add(cancel_image); + cancel_button.set_icon_name("go-previous-symbolic"); cancel_button.clicked.disconnect(on_cancel); cancel_button.clicked.connect(show_jid_add_view); ok_button.label = _("Join"); @@ -73,31 +70,30 @@ public class AddConferenceDialog : Gtk.Dialog { stack.transition_type = StackTransitionType.SLIDE_LEFT; stack.set_visible_child_name("details"); - animate_window_resize(); +// animate_window_resize(); } private void setup_headerbar() { - cancel_button = new Button() { visible=true }; - - ok_button = new Button() { can_focus=true, can_default=true, visible=true }; + ok_button = new Button() { can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); if (Util.use_csd()) { HeaderBar header_bar = get_header_bar() as HeaderBar; - header_bar.show_close_button = false; + header_bar.show_title_buttons = false; header_bar.pack_start(cancel_button); header_bar.pack_end(ok_button); - ok_button.has_default = true; +// ok_button.has_default = true; } } private void setup_jid_add_view() { conference_list = new ConferenceList(stream_interactor); - conference_list.row_activated.connect(() => { ok_button.clicked(); }); + conference_list_box = conference_list.get_list_box(); + conference_list_box.row_activated.connect(() => { ok_button.clicked(); }); - select_fragment = new SelectJidFragment(stream_interactor, conference_list, stream_interactor.get_accounts()); + select_fragment = new SelectJidFragment(stream_interactor, conference_list_box, stream_interactor.get_accounts()); select_fragment.add_jid.connect((row) => { AddGroupchatDialog dialog = new AddGroupchatDialog(stream_interactor); dialog.set_transient_for(this); @@ -109,23 +105,23 @@ public class AddConferenceDialog : Gtk.Dialog { }); Box wrap_box = new Box(Orientation.VERTICAL, 0) { visible=true }; - wrap_box.add(select_fragment); + wrap_box.append(select_fragment); stack.add_named(wrap_box, "select"); if (!Util.use_csd()) { Box box = new Box(Orientation.HORIZONTAL, 5) { halign=Align.END, margin_bottom=15, margin_start=80, margin_end=80, visible=true }; - Button ok_button = new Button() { label=_("Next"), sensitive=false, halign = Align.END, can_focus=true, can_default=true, visible=true }; + Button ok_button = new Button.with_label(_("Next")) { sensitive=false, halign = Align.END, can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); ok_button.clicked.connect(on_next_button_clicked); select_fragment.notify["done"].connect(() => { ok_button.sensitive = select_fragment.done; }); - Button cancel_button = new Button() { label=_("Cancel"), halign=Align.START, visible=true }; + Button cancel_button = new Button.with_label(_("Cancel")) { halign=Align.START, visible=true }; cancel_button.clicked.connect(on_cancel); - box.add(cancel_button); - box.add(ok_button); - wrap_box.add(box); + box.append(cancel_button); + box.append(ok_button); + wrap_box.append(box); - ok_button.has_default = true; +// ok_button.has_default = true; } } @@ -134,22 +130,22 @@ public class AddConferenceDialog : Gtk.Dialog { details_fragment.joined.connect(() => this.close()); Box wrap_box = new Box(Orientation.VERTICAL, 0) { visible=true }; - wrap_box.add(details_fragment); + wrap_box.append(details_fragment); if (!Util.use_csd()) { Box box = new Box(Orientation.HORIZONTAL, 5) { halign=Align.END, margin_bottom=15, margin_start=80, margin_end=80, visible=true }; - Button ok_button = new Button() { label=_("Join"), halign = Align.END, can_focus=true, can_default=true, visible=true }; + Button ok_button = new Button.with_label(_("Join")) { halign = Align.END, can_focus=true, visible=true }; ok_button.get_style_context().add_class("suggested-action"); details_fragment.notify["done"].connect(() => { ok_button.sensitive = select_fragment.done; }); details_fragment.ok_button = ok_button; - Button cancel_button = new Button() { label=_("Back"), halign=Align.START, visible=true }; + Button cancel_button = new Button.with_label(_("Back")) { halign=Align.START, visible=true }; cancel_button.clicked.connect(show_jid_add_view); - box.add(cancel_button); - box.add(ok_button); + box.append(cancel_button); + box.append(ok_button); - wrap_box.add(box); + wrap_box.append(box); } stack.add_named(wrap_box, "details"); } @@ -164,8 +160,9 @@ public class AddConferenceDialog : Gtk.Dialog { private void on_next_button_clicked() { details_fragment.clear(); - ListRow? row = conference_list.get_selected_row() as ListRow; - ConferenceListRow? conference_row = conference_list.get_selected_row() as ConferenceListRow; + + ListRow? row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row().get_child() as ListRow : null; + ConferenceListRow? conference_row = conference_list_box.get_selected_row() != null ? conference_list_box.get_selected_row() as ConferenceListRow : null; if (conference_row != null) { details_fragment.account = conference_row.account; details_fragment.jid = conference_row.bookmark.jid.to_string(); @@ -184,10 +181,11 @@ public class AddConferenceDialog : Gtk.Dialog { } private void animate_window_resize() { - int def_height, curr_width, curr_height; - get_size(out curr_width, out curr_height); - stack.get_preferred_height(null, out def_height); - int difference = def_height - curr_height; + int curr_height = get_size(Orientation.VERTICAL); + int curr_width = get_size(Orientation.HORIZONTAL); + var natural_size = new Requisition(); + stack.get_preferred_size(null, out natural_size); + int difference = natural_size.height - curr_height; Timer timer = new Timer(); Timeout.add((int) (stack.transition_duration / 30), () => { @@ -195,7 +193,8 @@ public class AddConferenceDialog : Gtk.Dialog { timer.elapsed(out microsec); ulong millisec = microsec / 1000; double partial = double.min(1, (double) millisec / stack.transition_duration); - resize(curr_width, (int) (curr_height + difference * partial)); + var a = this.list_toplevels().nth_data(0); + set_size_request(curr_width, (int) (curr_height + difference * partial)); return millisec < stack.transition_duration; }); } -- cgit v1.2.3-54-g00ecf