Consistently "use strictures 2" in all source files.
[tails-persistence-setup.git] / lib / Tails / Persistence / Step / Configure.pm
blob8485f2de14c61baa79e5bd11466a2e50b9b4517e
1 =head1 NAME
3 Tails::Persistence::Step::Configure - configure which bits are persistent
5 =cut
7 package Tails::Persistence::Step::Configure;
9 use 5.10.1;
10 use strictures 2;
12 use Glib qw{TRUE FALSE};
14 use Carp::Assert::More;
15 use Number::Format qw(:subs);
16 use Tails::Persistence::Configuration::Button;
17 use Try::Tiny;
19 use Locale::gettext;
20 use POSIX;
21 setlocale(LC_MESSAGES, "");
22 textdomain("tails-persistence-setup");
24 use Moo;
25 use MooX::late;
26 use MooX::HandlesVia;
27 use namespace::clean;
30 =head1 ATTRIBUTES
32 =cut
34 has 'configuration' => (
35 required => 1,
36 is => 'ro',
37 isa => 'Tails::Persistence::Configuration',
40 has 'persistence_partition_device_file' => (
41 required => 1,
42 is => 'ro',
43 isa => 'Str',
45 has 'persistence_partition_size' => (
46 required => 1,
47 is => 'ro',
48 isa => 'Int',
51 has 'list_box' => (
52 lazy_build => 1,
53 is => 'ro',
54 isa => 'Gtk3::VBox',
57 has 'buttons' => (
58 lazy_build => 1,
59 is => 'ro',
60 isa => 'ArrayRef[Tails::Persistence::Configuration::Button]',
61 handles_via => [ 'Array' ],
62 handles => {
63 all_buttons => 'elements',
64 push_button => 'push',
69 =head1 CONSTRUCTORS
71 =cut
73 sub BUILD {
74 my $self = shift;
76 # Force initialization in the right order
77 assert_defined($self->configuration);
78 assert_defined($self->buttons);
79 assert_defined($self->list_box);
81 $self->title->set_text($self->encoding->decode(gettext(
82 q{Persistence wizard - Persistent volume configuration}
83 )));
84 $self->subtitle->set_text($self->encoding->decode(gettext(
85 q{Specify the files that will be saved in the persistent volume}
86 )));
87 $self->description->set_markup($self->encoding->decode(sprintf(
88 # TRANSLATORS: partition, size, device vendor, device model
89 gettext(q{The selected files will be stored in the encrypted partition %s (%s), on the <b>%s %s</b> device.}),
90 $self->persistence_partition_device_file,
91 format_bytes($self->persistence_partition_size, mode => "iec"),
92 $self->drive_vendor,
93 $self->drive_model
94 )));
95 $self->go_button->set_label($self->encoding->decode(gettext(q{Save})));
96 $self->go_button->set_sensitive(TRUE);
99 sub _build_main_box {
100 my $self = shift;
101 my $box = Gtk3::VBox->new();
102 $box->set_spacing(6);
103 $box->pack_start($self->title, FALSE, FALSE, 0);
104 $box->pack_start($self->subtitle, FALSE, FALSE, 0);
105 $box->pack_start($self->description, FALSE, FALSE, 0);
107 my $viewport = Gtk3::Viewport->new;
108 $viewport->set_shadow_type('GTK_SHADOW_NONE');
109 $viewport->add($self->list_box);
110 my $scrolled_win = Gtk3::ScrolledWindow->new;
111 $scrolled_win->set_policy('automatic', 'automatic');
112 $scrolled_win->add($viewport);
113 $box->pack_start($scrolled_win, TRUE, TRUE, 0);
115 $box->pack_start($self->status_area, FALSE, FALSE, 0);
117 my $button_alignment = Gtk3::Alignment->new(1.0, 0, 0.2, 1.0);
118 $button_alignment->set_padding(0, 0, 10, 10);
119 $button_alignment->add($self->go_button);
120 $box->pack_start($button_alignment, FALSE, FALSE, 0);
122 return $box;
125 sub _build_buttons {
126 my $self = shift;
128 map {
129 Tails::Persistence::Configuration::Button->new(atom => $_)
130 } $self->configuration->all_atoms
134 sub _build_list_box {
135 my $self = shift;
136 my $box = Gtk3::VBox->new();
137 $box->set_spacing(6);
138 $box->pack_start($_->main_widget, FALSE, FALSE, 0) foreach $self->all_buttons;
139 $self->refresh_buttons;
141 return $box;
145 =head1 METHODS
147 =cut
149 sub operation_finished {
150 my $self = shift;
151 my $error = shift;
152 if ($error) {
153 $self->working(0);
154 say STDERR "$error";
155 $self->subtitle->set_text($self->encoding->decode(gettext(q{Failed})));
156 $self->description->set_text($error);
158 else {
159 say STDERR "done.";
160 $self->working(0);
161 $self->success_callback->();
165 sub go_button_pressed {
166 my $self = shift;
167 $self->list_box->hide;
168 $self->working(1);
169 $self->subtitle->set_text(
170 $self->encoding->decode(gettext(q{Saving...})),
172 $self->description->set_text(
173 $self->encoding->decode(gettext(q{Saving persistence configuration...})),
176 my $error;
177 try {
178 $self->go_callback->();
179 } catch {
180 $error = $@;
182 $self->operation_finished($error);
185 sub refresh_buttons {
186 my $self = shift;
187 $_->refresh_display foreach $self->all_buttons;
190 with 'Tails::Persistence::Role::StatusArea';
191 with 'Tails::Persistence::Role::SetupStep';
193 no Moo;