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(),
)
}
}
|