Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MainWindow: use Adw.NavigationView #802

Merged
merged 13 commits into from
Sep 28, 2024
149 changes: 74 additions & 75 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,18 @@ public class Installer.MainWindow : Gtk.Window {
private const uint64 MINIMUM_SPACE = 15 * ONE_GB;

private Gtk.Label infobar_label;
private Adw.Leaflet leaflet;
private Adw.NavigationView navigation_view;
private LanguageView language_view;
private TryInstallView try_install_view;
private KeyboardLayoutView keyboard_layout_view;
private bool check_ignored = false;
private uint orca_timeout_id = 0;

construct {
language_view = new LanguageView ();

leaflet = new Adw.Leaflet () {
can_navigate_back = true,
can_unfold = false,
homogeneous = false
};
leaflet.append (language_view);
navigation_view = new Adw.NavigationView ();
navigation_view.add (language_view);

infobar_label = new Gtk.Label ("") {
use_markup = true
Expand All @@ -63,7 +60,7 @@ public class Installer.MainWindow : Gtk.Window {
battery_infobar.add_css_class (Granite.STYLE_CLASS_FRAME);

var overlay = new Gtk.Overlay () {
child = leaflet
child = navigation_view
};
overlay.add_overlay (battery_infobar);

Expand Down Expand Up @@ -128,136 +125,138 @@ public class Installer.MainWindow : Gtk.Window {

return Source.REMOVE;
});

leaflet.notify["visible-child"].connect (() => {
update_navigation ();
});

leaflet.notify["child-transition-running"].connect (() => {
update_navigation ();
});
}

private void update_navigation () {
if (!leaflet.child_transition_running) {
// We need to rebuild the views to reflect language changes and forking paths
if (leaflet.visible_child == language_view || leaflet.visible_child == try_install_view) {
while (leaflet.get_adjacent_child (FORWARD) != null) {
leaflet.remove (leaflet.get_adjacent_child (FORWARD));
}
}
}
}

private void load_keyboard_view () {
var keyboard_layout_view = new KeyboardLayoutView ();
keyboard_layout_view = new KeyboardLayoutView ();
try_install_view = new TryInstallView ();

leaflet.append (keyboard_layout_view);
leaflet.append (try_install_view);
navigation_view.push (keyboard_layout_view);

leaflet.visible_child = keyboard_layout_view;
keyboard_layout_view.next_step.connect (() => {
navigation_view.push (try_install_view);
});

try_install_view.custom_step.connect (() => {
load_check_view ();
load_partitioning_view ();
load_drivers_view ();
leaflet.navigate (FORWARD);
if (check_ignored) {
load_partitioning_view ();
} else {
load_check_view ("custom");
}
});

try_install_view.next_step.connect (() => {
load_check_view ();
load_disk_view ();
load_encrypt_view ();
load_drivers_view ();
leaflet.navigate (FORWARD);
if (check_ignored) {
load_disk_view ();
} else {
load_check_view ("standard");
}
});
}

private void load_disk_view () {
var disk_view = new DiskView ();
leaflet.append (disk_view);
navigation_view.push (disk_view);

disk_view.load.begin (MINIMUM_SPACE);
disk_view.cancel.connect (() => leaflet.navigate (BACK));
disk_view.cancel.connect (() => navigation_view.pop ());
disk_view.next_step.connect (() => load_encrypt_view ());
}

private void load_check_view () {
if (check_ignored) {
return;
}

private void load_check_view (string path) {
danirabbit marked this conversation as resolved.
Show resolved Hide resolved
var check_view = new Installer.CheckView ();
if (check_view.has_messages) {
leaflet.append (check_view);
}

check_view.cancel.connect (() => leaflet.navigate (BACK));
check_view.cancel.connect (() => navigation_view.pop ());

check_view.next_step.connect (() => {
check_ignored = true;
leaflet.navigate (FORWARD);

if (path == "custom") {
load_partitioning_view ();
} else if (path == "standard") {
load_disk_view ();
}
});

if (check_view.has_messages) {
navigation_view.push (check_view);
} else {
if (path == "custom") {
load_partitioning_view ();
} else if (path == "standard") {
load_disk_view ();
}
}
}

private void load_encrypt_view () {
var encrypt_view = new EncryptView ();
leaflet.append (encrypt_view);
encrypt_view.cancel.connect (() => navigation_view.pop ());
encrypt_view.next_step.connect (load_drivers_view);

encrypt_view.cancel.connect (() => {
leaflet.visible_child = try_install_view;
});
navigation_view.push (encrypt_view);
}

private void load_partitioning_view () {
var partitioning_view = new PartitioningView (MINIMUM_SPACE);
leaflet.append (partitioning_view);
navigation_view.push (partitioning_view);

partitioning_view.next_step.connect (() => {
unowned Configuration config = Configuration.get_default ();
config.luks = (owned) partitioning_view.luks;
config.mounts = (owned) partitioning_view.mounts;
leaflet.navigate (FORWARD);
load_drivers_view ();
});
}

private void load_drivers_view () {
var drivers_view = new DriversView ();
leaflet.append (drivers_view);

drivers_view.next_step.connect (() => load_progress_view ());

navigation_view.push (drivers_view);
}

private void load_progress_view () {
var progress_view = new ProgressView ();

leaflet.append (progress_view);
leaflet.visible_child = progress_view;
leaflet.can_navigate_back = false;
progress_view.on_success.connect (() => {
var success_view = new SuccessView ();
navigation_view.push (success_view);

progress_view.on_success.connect (() => load_success_view ());
success_view.shown.connect (() => {
navigation_view.replace ({ success_view });
});
});

progress_view.on_error.connect (() => {
load_error_view (progress_view.get_log ());
});
progress_view.start_installation ();
}

private void load_success_view () {
var success_view = new SuccessView ();
leaflet.append (success_view);
leaflet.visible_child = success_view;
progress_view.shown.connect (() => {
navigation_view.replace ({ progress_view });
});

navigation_view.push (progress_view);
progress_view.start_installation ();
}

private void load_error_view (string log) {
var error_view = new ErrorView (log);
leaflet.append (error_view);
leaflet.visible_child = error_view;

error_view.retry_install.connect (() => {
leaflet.visible_child = try_install_view;
leaflet.can_navigate_back = true;
navigation_view.replace ({
language_view,
keyboard_layout_view,
try_install_view,
error_view
});
navigation_view.pop ();
});

error_view.shown.connect (() => {
navigation_view.replace ({ error_view });
});

navigation_view.push (error_view);
}

private void set_infobar_string () {
Expand Down
1 change: 1 addition & 0 deletions src/Views/AbstractInstallerView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public abstract class AbstractInstallerView : Adw.NavigationPage {
public bool cancellable { get; construct; }

public signal void cancel ();
public signal void next_step ();

protected Gtk.Box title_area;
protected Gtk.Box content_area;
Expand Down
2 changes: 0 additions & 2 deletions src/Views/CheckView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class Installer.CheckView : AbstractInstallerView {
// Minimum 1GB
public const uint64 MINIMUM_MEMORY = 1 * ONE_GB;

public signal void next_step ();

private Gtk.Box message_box;
public bool has_messages {
get {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/DiskView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class Installer.DiskView : AbstractInstallerView {
sensitive = Installer.App.test_mode
};
next_button.add_css_class (Granite.STYLE_CLASS_SUGGESTED_ACTION);
next_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (FORWARD));
next_button.clicked.connect (() => next_step ());

action_box_end.append (next_button);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Views/DriversView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/

public class DriversView : AbstractInstallerView {
public signal void next_step ();

construct {
var image = new Gtk.Image.from_icon_name ("application-x-firmware") {
pixel_size = 128
Expand Down Expand Up @@ -75,7 +73,7 @@
content_area.append (message_box);

var back_button = new Gtk.Button.with_label (_("Back"));
back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.NavigationView) get_parent ()).pop ());
danirabbit marked this conversation as resolved.
Show resolved Hide resolved

var next_button = new Gtk.Button.with_label (_("Erase and Install"));
next_button.add_css_class (Granite.STYLE_CLASS_DESTRUCTIVE_ACTION);
Expand Down
2 changes: 1 addition & 1 deletion src/Views/EncryptView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public class EncryptView : AbstractInstallerView {
Configuration.get_default ().encryption_password = pw_entry.text;
}

((Adw.Leaflet) get_parent ()).navigate (FORWARD);
next_step ();
});

pw_entry.changed.connect (() => {
Expand Down
4 changes: 2 additions & 2 deletions src/Views/KeyboardLayoutView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class KeyboardLayoutView : AbstractInstallerView {
next_button.activate ();
});

back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.NavigationView) get_parent ()).pop ());

next_button.clicked.connect (() => {
unowned Gtk.ListBoxRow row = input_variant_widget.main_listbox.get_selected_row ();
Expand All @@ -92,7 +92,7 @@ public class KeyboardLayoutView : AbstractInstallerView {
return;
}

((Adw.Leaflet) get_parent ()).navigate (FORWARD);
next_step ();
});

input_variant_widget.main_listbox.row_activated.connect ((row) => {
Expand Down
2 changes: 0 additions & 2 deletions src/Views/LanguageView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class Installer.LanguageView : AbstractInstallerView {

private VariantWidget lang_variant_widget;

public signal void next_step ();

public LanguageView () {
lang_timeout = GLib.Timeout.add_seconds (3, timeout);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/

public class Installer.PartitioningView : AbstractInstallerView {
public signal void next_step ();

private Gtk.Button next_button;
private Gtk.Button modify_partitions_button;
private Gtk.Box disk_list;
Expand Down Expand Up @@ -150,7 +148,7 @@ public class Installer.PartitioningView : AbstractInstallerView {
action_box_end.append (back_button);
action_box_end.append (next_button);

back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.NavigationView) get_parent ()).pop ());
next_button.clicked.connect (() => next_step ());
}

Expand Down
3 changes: 1 addition & 2 deletions src/Views/TryInstallView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

public class Installer.TryInstallView : AbstractInstallerView {
public signal void custom_step ();
public signal void next_step ();

construct {
var type_image = new Gtk.Image.from_icon_name (Application.get_default ().application_id) {
Expand Down Expand Up @@ -87,7 +86,7 @@ public class Installer.TryInstallView : AbstractInstallerView {
action_box_end.append (back_button);
action_box_end.append (next_button);

back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.NavigationView) get_parent ()).pop ());

demo_button.toggled.connect (() => {
if (demo_button.active) {
Expand Down