patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 4755acc201d71d46de3eb9fa2fc7bcb6e3dadf7c 4215 bytes (raw)
name: tools/spectrum-installer/src/pages/disk_selection.rs 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
// SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2025-2026 Johannes Süllner <johannes.suellner@mailbox.org>

use super::{
    BUTTON_TEXT_SIZE, Event, MARGIN_LR, MARGIN_VERTICAL, Page, TITLE_TEXT_SIZE, UpdateResult,
    WINDOW_WIDTH,
};
use crate::{center_horizontal_in_container, destination_device::DestinationDevice};
use iced::{
    Length, Task,
    widget::{
        Scrollable, button, column,
        scrollable::{Direction, Scrollbar},
        space, text,
    },
};

pub struct PageDiskSelection {
    destination_device: Option<DestinationDevice>,
}

impl PageDiskSelection {
    pub fn new() -> Self {
        Self {
            destination_device: None,
        }
    }
}

#[derive(Clone, Debug)]
pub enum PageDiskSelectionEvent {
    Back,
    SelectDevice(DestinationDevice),
    ContinueWithDevice(DestinationDevice),
}

impl Page for PageDiskSelection {
    fn update(&mut self, event: Event) -> UpdateResult {
        if let Event::PageDiskSelection(page_disk_selection_event) = event {
            match page_disk_selection_event {
                PageDiskSelectionEvent::Back => {
                    return (
                        Some(Box::new(super::welcome::PageWelcome::new())),
                        Task::none(),
                    );
                }
                PageDiskSelectionEvent::SelectDevice(device) => {
                    self.destination_device = Some(device);
                }
                PageDiskSelectionEvent::ContinueWithDevice(device) => {
                    return (
                        Some(Box::new(super::confirmation::PageConfirmation::new(device))),
                        Task::none(),
                    );
                }
            }
        }
        (None, Task::none())
    }

    fn view(&self) -> iced::Element<'_, Event> {
        let destination_devices = DestinationDevice::get_destination_devices().unwrap_or(vec![]);

        let destination_selection = if destination_devices.is_empty() {
            column![text("No applicable devices to install Spectrum to found.")]
        } else {
            column(destination_devices.iter().map(|device| {
                button(super::layout::disk_element(&device))
                    .on_press(Event::PageDiskSelection(
                        PageDiskSelectionEvent::SelectDevice(device.clone()),
                    ))
                    .width(WINDOW_WIDTH - 2.0 * MARGIN_LR)
                    .style({
                        if self
                            .destination_device
                            .as_ref()
                            .is_some_and(|d| d.name == device.name)
                        {
                            button::success
                        } else {
                            button::primary
                        }
                    })
                    .into()
            }))
            .spacing(8)
            .into()
        };

        let main_content = column![
            space().height(MARGIN_VERTICAL),
            center_horizontal_in_container!(
                text("Select the device to install Spectrum to").size(TITLE_TEXT_SIZE)
            ),
            space().height(MARGIN_VERTICAL),
            center_horizontal_in_container!(
                Scrollable::new(destination_selection)
                    .height(Length::Fill)
                    .direction(Direction::Vertical(Scrollbar::new()))
            ),
            space().height(MARGIN_VERTICAL),
        ];

        super::layout::bottom_buttons_layout(
            [[
                (
                    text("Back").size(BUTTON_TEXT_SIZE).into(),
                    Some(Event::PageDiskSelection(PageDiskSelectionEvent::Back)),
                ),
                (
                    text("Next").size(BUTTON_TEXT_SIZE).into(),
                    match &self.destination_device {
                        None => None,
                        Some(device) => Some(Event::PageDiskSelection(
                            PageDiskSelectionEvent::ContinueWithDevice(device.clone()),
                        )),
                    },
                ),
            ]],
            main_content.into(),
        )
    }
}

debug log:

solving 4755acc ...
found 4755acc in https://inbox.spectrum-os.org/spectrum-devel/20260204175543.22164-3-johannes.suellner@mailbox.org/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20260204175543.22164-3-johannes.suellner@mailbox.org/
diff --git a/tools/spectrum-installer/src/pages/disk_selection.rs b/tools/spectrum-installer/src/pages/disk_selection.rs
new file mode 100644
index 0000000..4755acc

Checking patch tools/spectrum-installer/src/pages/disk_selection.rs...
Applied patch tools/spectrum-installer/src/pages/disk_selection.rs cleanly.

index at:
100644 4755acc201d71d46de3eb9fa2fc7bcb6e3dadf7c	tools/spectrum-installer/src/pages/disk_selection.rs

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).