Skip to content

Commit

Permalink
Replace Deck with Leaflet
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored and tintou committed May 1, 2024
1 parent 89c49e2 commit 9e70823
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 46 deletions.
73 changes: 37 additions & 36 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public interface UPower : GLib.Object {
public abstract bool on_battery { owned get; set; }
}

public class Installer.MainWindow : Hdy.Window {
public class Installer.MainWindow : Gtk.Window {
// We have to do it step by step because the vala compiler has overflows with big numbers.
private const uint64 ONE_GB = 1000 * 1000 * 1000;
// Minimum 15 GB
private const uint64 MINIMUM_SPACE = 15 * ONE_GB;

private Gtk.Label infobar_label;
private Hdy.Deck deck;
private Adw.Leaflet leaflet;
private LanguageView language_view;
private TryInstallView try_install_view;
private bool check_ignored = false;
Expand All @@ -38,10 +38,11 @@ public class Installer.MainWindow : Hdy.Window {
construct {
language_view = new LanguageView ();

deck = new Hdy.Deck () {
can_swipe_back = true
leaflet = new Adw.Leaflet () {
can_navigate_back = true,
can_unfold = false
};
deck.add (language_view);
leaflet.add (language_view);

infobar_label = new Gtk.Label ("") {
use_markup = true
Expand All @@ -61,7 +62,7 @@ public class Installer.MainWindow : Hdy.Window {
battery_infobar.get_style_context ().add_class ("frame");

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

Expand Down Expand Up @@ -126,21 +127,21 @@ public class Installer.MainWindow : Hdy.Window {
return Source.REMOVE;
});

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

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

private void update_navigation () {
if (!deck.transition_running) {
if (!leaflet.transition_running) {
// We need to rebuild the views to reflect language changes and forking paths
if (deck.visible_child == language_view || deck.visible_child == try_install_view) {
while (deck.get_adjacent_child (FORWARD) != null) {
deck.remove (deck.get_adjacent_child (FORWARD));
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));
}
}
}
Expand All @@ -150,33 +151,33 @@ public class Installer.MainWindow : Hdy.Window {
var keyboard_layout_view = new KeyboardLayoutView ();
try_install_view = new TryInstallView ();

deck.add (keyboard_layout_view);
deck.add (try_install_view);
leaflet.add (keyboard_layout_view);
leaflet.add (try_install_view);

deck.visible_child = keyboard_layout_view;
leaflet.visible_child = keyboard_layout_view;

try_install_view.custom_step.connect (() => {
load_check_view ();
load_partitioning_view ();
load_drivers_view ();
deck.navigate (FORWARD);
leaflet.navigate (FORWARD);
});

try_install_view.next_step.connect (() => {
load_check_view ();
load_disk_view ();
load_encrypt_view ();
load_drivers_view ();
deck.navigate (FORWARD);
leaflet.navigate (FORWARD);
});
}

private void load_disk_view () {
var disk_view = new DiskView ();
deck.add (disk_view);
leaflet.add (disk_view);

disk_view.load.begin (MINIMUM_SPACE);
disk_view.cancel.connect (() => deck.navigate (BACK));
disk_view.cancel.connect (() => leaflet.navigate (BACK));
}

private void load_check_view () {
Expand All @@ -186,51 +187,51 @@ public class Installer.MainWindow : Hdy.Window {

var check_view = new Installer.CheckView ();
if (check_view.has_messages) {
deck.add (check_view);
leaflet.add (check_view);
}

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

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

private void load_encrypt_view () {
var encrypt_view = new EncryptView ();
deck.add (encrypt_view);
leaflet.add (encrypt_view);

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

private void load_partitioning_view () {
var partitioning_view = new PartitioningView (MINIMUM_SPACE);
deck.add (partitioning_view);
leaflet.add (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;
deck.navigate (FORWARD);
leaflet.navigate (FORWARD);
});
}

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

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

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

deck.add (progress_view);
deck.visible_child = progress_view;
deck.can_swipe_back = false;
leaflet.add (progress_view);
leaflet.visible_child = progress_view;
leaflet.can_swipe_back = false;

progress_view.on_success.connect (() => load_success_view ());

Expand All @@ -242,18 +243,18 @@ public class Installer.MainWindow : Hdy.Window {

private void load_success_view () {
var success_view = new SuccessView ();
deck.add (success_view);
deck.visible_child = success_view;
leaflet.add (success_view);
leaflet.visible_child = success_view;
}

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

error_view.retry_install.connect (() => {
deck.visible_child = try_install_view;
deck.can_swipe_back = true;
leaflet.visible_child = try_install_view;
leaflet.can_swipe_back = true;
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Views/DiskView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class Installer.DiskView : AbstractInstallerView {
sensitive = Installer.App.test_mode
};
next_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
next_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (FORWARD));
next_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (FORWARD));

action_area.add (next_button);

Expand Down
2 changes: 1 addition & 1 deletion src/Views/DriversView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
content_area.attach (message_grid, 1, 0, 1, 2);

var back_button = new Gtk.Button.with_label (_("Back"));
back_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));

var next_button = new Gtk.Button.with_label (_("Erase and Install"));
next_button.get_style_context ().add_class (Gtk.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 @@ -199,7 +199,7 @@ public class EncryptView : AbstractInstallerView {
Configuration.get_default ().encryption_password = pw_entry.text;
}

((Hdy.Deck) get_parent ()).navigate (FORWARD);
((Adw.Leaflet) get_parent ()).navigate (FORWARD);
});

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 @@ -82,7 +82,7 @@ public class KeyboardLayoutView : AbstractInstallerView {
next_button.activate ();
});

back_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (BACK));
back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));

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

((Hdy.Deck) get_parent ()).navigate (FORWARD);
((Adw.Leaflet) get_parent ()).navigate (FORWARD);
});

input_variant_widget.main_listbox.row_activated.connect ((row) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Views/PartitioningView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public class Installer.PartitioningView : AbstractInstallerView {
action_area.add (back_button);
action_area.add (next_button);

back_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (Hdy.NavigationDirection.BACK));
back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (Hdy.NavigationDirection.BACK));
next_button.clicked.connect (() => next_step ());

show_all ();
Expand Down
2 changes: 1 addition & 1 deletion src/Views/TryInstallView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Installer.TryInstallView : AbstractInstallerView {
action_area.add (back_button);
action_area.add (next_button);

back_button.clicked.connect (() => ((Hdy.Deck) get_parent ()).navigate (Hdy.NavigationDirection.BACK));
back_button.clicked.connect (() => ((Adw.Leaflet) get_parent ()).navigate (BACK));

demo_button.clicked.connect (() => {
if (demo_button.active) {
Expand Down
7 changes: 4 additions & 3 deletions src/Widgets/VariantWidget.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class VariantWidget : Gtk.Frame {
private Gtk.Button back_button;
private Gtk.Box variant_box;
private Gtk.Label variant_title;
private Hdy.Deck deck;
private Adw.Leaflet deck;

construct {
main_listbox = new Gtk.ListBox ();
Expand Down Expand Up @@ -68,8 +68,9 @@ public class VariantWidget : Gtk.Frame {
variant_box.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
variant_box.add (variant_scrolled);

deck = new Hdy.Deck () {
can_swipe_back = true
deck = new Adw.Leaflet () {
can_navigate_back = true,
can_unfold = false
};
deck.add (main_scrolled);
deck.add (variant_box);
Expand Down

0 comments on commit 9e70823

Please sign in to comment.