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
124
125
126
127
128
129
130
131
132
133
134
| | // SPDX-License-Identifier: EUPL-1.2+
// SPDX-FileCopyrightText: 2025 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;
use iced::{
Length, Task,
widget::{
Scrollable, Space, button, column,
scrollable::{Direction, Scrollbar},
text,
},
};
use lsblk::BlockDevice;
pub struct PageDiskSelection {
destination_device: Option<BlockDevice>,
}
impl PageDiskSelection {
pub fn new() -> Self {
Self {
destination_device: None,
}
}
}
#[derive(Clone, Debug)]
pub enum PageDiskSelectionEvent {
Back,
SelectDevice(BlockDevice),
ContinueWithDevice(BlockDevice),
}
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 mut block_devices = BlockDevice::list().expect("Failed to get block devices");
block_devices.sort_by_key(|device| device.name.clone());
let mut possible_block_devices = block_devices
.iter()
.filter(|device| {
BlockDevice::is_disk(device)
&& !&device.name.starts_with("loop")
&& !&device.name.starts_with("sr")
})
.peekable();
let destinations: iced::Element<Event> = if possible_block_devices.peek().is_none() {
text("No applicable devices to install Spectrum to found.").into()
} else {
column(possible_block_devices.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.fullname == device.fullname)
{
button::success
} else {
button::primary
}
})
.into()
}))
.spacing(8)
.into()
};
let main_content = column![
Space::with_height(MARGIN_VERTICAL),
center_horizontal_in_container!(
text("Select the device to install Spectrum to").size(TITLE_TEXT_SIZE)
),
Space::with_height(MARGIN_VERTICAL),
center_horizontal_in_container!(
Scrollable::new(destinations)
.height(Length::Fill)
.direction(Direction::Vertical(Scrollbar::new()))
),
Space::with_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(),
)
}
}
|