Debian Codegraph @

joy-theme/plymouth/joy.script

raw
1 # ubuntu-logo.script - boot splash plugin
2 #
3 # Copyright (C) 2009 Canonical Ltd.
4 # Copyright © 2010 Aurélien Couderc <[email protected]>
5 # Copyright © 2012 Jonathan Carter <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21 # Written by: Alberto Milone <[email protected]>
22 #
23 # Based on the example provided with the "script plugin" written by:
24 # Charlie Brej <[email protected]>
25 #
26
27 bg_image = Image("background.png");
28
29 # Compute screen/image ratio and scale the background accordingly
30 window_max_width = Window.GetX() * 2 + Window.GetWidth();
31 window_max_height = Window.GetY() * 2 + Window.GetHeight();
32 screen_ratio = window_max_width / window_max_height;
33 bg_image_ratio = bg_image.GetWidth() / bg_image.GetHeight();
34 if (screen_ratio > bg_image_ratio)
35 bg_scale_factor = window_max_width / bg_image.GetWidth();
36 else
37 bg_scale_factor = window_max_height / bg_image.GetHeight();
38 scaled_bg_image = bg_image.Scale(bg_image.GetWidth() * bg_scale_factor,
39 bg_image.GetHeight() * bg_scale_factor);
40
41 # Display background
42 bg_sprite = Sprite(scaled_bg_image);
43 bg_sprite.SetPosition(Window.GetX() + Window.GetWidth() / 2 - scaled_bg_image.GetWidth() / 2,
44 Window.GetY() + Window.GetHeight() / 2 - scaled_bg_image.GetHeight() / 2,
45 -10000);
46
47
48
49 # Set the text colour in (rgb / 256)
50 text_colour.red = 0.0;
51 text_colour.green = 0.0;
52 text_colour.blue = 0.0;
53
54 # Tinted text #988592
55 tinted_text_colour.red = 0.0;
56 tinted_text_colour.green = 0.0;
57 tinted_text_colour.blue = 0.0;
58
59 # Action Text - #ffffff - RGB 255 255 255
60 action_text_colour.red = 1.0;
61 action_text_colour.green = 1.0;
62 action_text_colour.blue = 1.0;
63
64 # Orange - #ff4012 - RGB 255 64 18
65 debugsprite = Sprite();
66 debugsprite_bottom = Sprite();
67 debugsprite_medium = Sprite();
68
69 # are we currently prompting for a password?
70 prompt_active = 0;
71
72 # General purpose function to create text
73 fun WriteText (text, colour) {
74 image = Image.Text (text, colour.red, colour.green, colour.blue);
75 return image;
76 }
77
78 fun ImageToText (text) {
79 image = WriteText (text, text_colour);
80 return image;
81 }
82
83 fun ImageToTintedText (text) {
84 image = WriteText (text, tinted_text_colour);
85 return image;
86 }
87
88 fun ImageToActionText (text) {
89 image = WriteText (text, action_text_colour);
90 return image;
91 }
92
93 fun Debug(text) {
94 debugsprite.SetImage(ImageToText (text));
95 }
96
97 fun DebugBottom(text) {
98 debugsprite_bottom.SetImage(ImageToText (text));
99 debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
100 }
101
102 fun DebugMedium(text) {
103 debugsprite_medium.SetImage(ImageToText (text));
104 debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 60), 1);
105 }
106
107 fun TextYOffset() {
108 local.y;
109 local.text_height;
110 local.min_height;
111
112 # Put the 1st line below the logo + some spacing
113 y = logo.y + logo.height + (progress_indicator.bullet_height * 7 ); # + logo_spacing;
114
115 text_height = first_line_height * 7.5;
116
117 min_height = window_max.height;
118 if (y + text_height > min_height)
119 y = min_height - text_height;
120
121 if (y < progress_indicator.y + progress_indicator.height)
122 return progress_indicator.y + progress_indicator.height;
123 return y;
124 }
125
126 #------------------------------String functions-------------------------------
127
128 # This is the equivalent for strstr()
129 fun StringString(string, substring) {
130 start = 0;
131 while (String(string).CharAt (start)) {
132 walk = 0;
133 while (String(substring).CharAt (walk) == String(string).CharAt (start + walk) ) {
134 walk++;
135 if (!String(substring).CharAt (walk)) return start;
136 }
137 start++;
138 }
139
140 return NULL;
141 }
142
143 fun StringLength (string) {
144 index = 0;
145 while (String(string).CharAt(index)) index++;
146 return index;
147 }
148
149 fun StringCopy (source, beginning, end) {
150 local.destination = "";
151 for (index = beginning; ( ( (end == NULL) || (index <= end) ) && (String(source).CharAt(index)) ); index++) {
152 local.destination += String(source).CharAt(index);
153 }
154
155 return local.destination;
156 }
157
158 fun StringReplace (source, pattern, replacement) {
159 local.found = StringString(source, pattern);
160 if (local.found == NULL)
161 return source;
162
163 local.new_string = StringCopy (source, 0, local.found - 1) +
164 replacement +
165 StringCopy (source, local.found + StringLength(pattern), NULL);
166
167 return local.new_string;
168 }
169
170 # it makes sense to use it only for
171 # numbers up to 100
172 fun StringToInteger (str) {
173 int = -1;
174 for (i=0; i<=100; i++) {
175 if (i+"" == str) {
176 int = i;
177 break;
178 }
179 }
180 return int;
181 }
182
183 #-----------------------------------------------------------------------------
184 # Previous background colour
185 # #300a24 --> 0.19, 0.04, 0.14
186 # New background colour
187 # #2c001e --> 0.16, 0.00, 0.12
188 #
189 Window.SetBackgroundTopColor (0.39, 0.43, 0.51); # Nice colour on top of the screen fading to
190 Window.SetBackgroundBottomColor (0.39, 0.43, 0.51); # an equally nice colour on the bottom
191
192 bits_per_pixel = Window.GetBitsPerPixel ();
193 if (bits_per_pixel == 4) {
194 logo_filename = "debian_logo16.png";
195 progress_dot_off_filename = "progress_dot_off16.png";
196 progress_dot_on_filename = "progress_dot_on16.png";
197 password_dot_filename = "password_dot.png";
198 password_field_filename = "password_field16.png";
199 } else {
200 logo_filename = "debian_logo.png";
201 progress_dot_off_filename = "progress_dot_off.png";
202 progress_dot_on_filename = "progress_dot_on.png";
203 password_dot_filename = "password_dot.png";
204 password_field_filename = "password_field.png";
205 }
206
207 logo.image = Image (logo_filename);
208 logo.sprite = Sprite ();
209 logo.sprite.SetImage (logo.image);
210 logo.width = logo.image.GetWidth ();
211 logo.height = logo.image.GetHeight ();
212 logo.x = Window.GetX () + Window.GetWidth () / 2 - logo.width / 2;
213 logo.y = Window.GetY () + Window.GetHeight () / 2 - logo.height;
214 logo.z = 1000;
215 logo.sprite.SetX (logo.x);
216 logo.sprite.SetY (logo.y);
217 logo.sprite.SetZ (logo.z);
218 logo.sprite.SetOpacity (1);
219
220 # Spacing below the logo - in pixels
221 logo_spacing = logo.height * 4;
222
223 message_notification[0].image = ImageToTintedText ("");
224 message_notification[1].image = ImageToTintedText ("");
225 fsck_notification.image = ImageToActionText ("");
226
227 status = "normal";
228
229 progress_indicator.bullet_off = Image (progress_dot_off_filename);
230 progress_indicator.bullet_on = Image (progress_dot_on_filename);
231 progress_indicator.bullet_width = progress_indicator.bullet_off.GetWidth ();
232 progress_indicator.bullet_height = progress_indicator.bullet_off.GetHeight ();
233 progress_indicator.bullet_hspacing = progress_indicator.bullet_width * 1.1;
234 progress_indicator.width = progress_indicator.bullet_width * 5;
235 progress_indicator.height = progress_indicator.bullet_height;
236 progress_indicator.y = logo.y + logo.height + (logo.height / 4);
237 progress_indicator.x = Window.GetX () + Window.GetWidth () / 2 - progress_indicator.width / 2; # logo.x + 26;
238
239 # use a fixed string with ascending and descending stems to calibrate the
240 # bounding box for the first message, so the messages below don't move up
241 # and down according to *their* height.
242 first_line_height = ImageToTintedText ("AfpqtM").GetHeight();
243
244 # if the user has a 640x480 or 800x600 display, we can't quite fit everything
245 # (including passphrase prompts) with the target spacing, so scoot the text up
246 # a bit if needed.
247 top_of_the_text = TextYOffset();
248
249 #-----------------------------------------Logo functions------------------------------
250
251 # Call this when updating the screen
252 fun draw_logo () {
253 logo.sprite.SetX (logo.x);
254 logo.sprite.SetY (logo.y);
255 logo.sprite.SetZ (logo.z);
256 logo.sprite.SetOpacity (1);
257 }
258
259
260 #-----------------------------------------Progress Indicator--------------------------
261 fun set_progress_indicator () {
262
263
264 # Here we assume that we can store half bullets on each half of the screen
265 # together with some spacing
266 local.x = progress_indicator.x;
267
268 for (index = 0; index <= 4; index++) {
269 # Set the "off" bullets
270 progress_indicator.bullets_off[index].sprite = Sprite (progress_indicator.bullet_off);
271 progress_indicator.bullets_off[index].sprite.SetPosition (local.x, progress_indicator.y, 1000);
272 progress_indicator.bullets_off[index].x = local.x;
273 progress_indicator.bullets_off[index].y = progress_indicator.y;
274 progress_indicator.bullets_off[index].sprite.SetOpacity (1);
275
276 #local.debug_medium_string = "Progress indicator " + index + ": x = " + progress_indicator.bullets_off[index].x +
277 # ", y = " + progress_indicator.bullets_off[index].y + ", logo width = " + logo.width +
278 # ", logo height = " + logo.height + " " + screen_width + " " + screen_height;
279 #
280 #(index % 2) && DebugMedium (local.debug_medium_string) || DebugBottom (local.debug_medium_string);
281
282 # Set the "on" bullets on top of the "off" bullets and make them transparent
283 progress_indicator.bullets_on[index].sprite = Sprite (progress_indicator.bullet_on);
284 progress_indicator.bullets_on[index].x = progress_indicator.bullets_off[index].x;
285 progress_indicator.bullets_on[index].y = progress_indicator.bullets_off[index].y;
286 progress_indicator.bullets_on[index].sprite.SetPosition (progress_indicator.bullets_on[index].x, progress_indicator.bullets_on[index].y, 10000);
287
288 progress_indicator.bullets_on[index].sprite.SetOpacity (0);
289
290 local.x += progress_indicator.bullet_hspacing;
291 }
292 #local.debug_string = "Progress indicator: x1 = " + progress_indicator.x + ", x2 = " + local.x + ", y = " + progress_indicator.y +
293 # ", x logo = " + logo.x + ", y logo = " + logo.y + ", indicator width = " + progress_indicator.width;
294 #Debug(progress_indicator.bullets_off[0].x);
295 }
296
297
298 # We have 2 bullets, one on top of the other:
299 # The white one is on top of the red one and the former should
300 # slowly fade so as to get a nice transition effect.
301 fun switch_on_bullet (bullets_off, bullets_on, bullet_number, opacity) {
302 local.x = bullets_on[bullet_number].x;
303 local.y = bullets_on[bullet_number].y;
304 local.z = bullets_on[bullet_number].z;
305
306 # Hide the bullets which are off
307 bullets_off[bullet_number].sprite.SetOpacity (0);
308
309 # Show the bullets which are on
310 bullets_on[bullet_number].sprite.SetPosition (local.x, local.y, local.z);
311 bullets_on[bullet_number].sprite.SetOpacity (opacity);
312
313 # Bump the number of times we have switched on bullets
314 global.times_bullets_switched++;
315 }
316
317 fun switch_off_bullets () {
318 # Debug("Switching off progress indicator");
319
320 set_progress_indicator ();
321 global.times_bullets_switched = 0;
322 global.on_off = 1;
323 }
324
325 # This is something that we can call when we exit
326 fun switch_on_bullets () {
327 # Debug("Switching off progress indicator");
328 if (!global.progress_indicator.bullets_on) set_progress_indicator ();
329 local = global.progress_indicator;
330
331 for (index = 0; bullets_on[index]; index++) {
332 switch_on_bullet (bullets_off, bullets_on, index, 1.0);
333 }
334 }
335
336
337 # Implement in boot progress callback
338 fun animate_progress_indicator (progress, time) {
339 if (global.progress_time == NULL) {
340 global.progress_time = progress; #time;
341 switch_off_bullets ();
342 }
343
344 # Debug ("progress = " + progress + ", time = " + time + " times switched = " + global.times_bullets_switched + " on_off " + global.on_off);
345
346 # if (global.times_bullets_switched == NULL)
347 # global.times_bullets_switched = 5;
348
349 # if (global.on_off == NULL)
350 # global.on_off = 0;
351
352 if ((progress - global.progress_time) >= 1.0) {
353 global.progress_time = progress;
354
355 if (global.times_bullets_switched == 5) {
356 # Change which bullets are switched on
357 # and which ones are switched off
358 global.on_off = !global.on_off;
359 global.times_bullets_switched = 0;
360 }
361
362 if (global.on_off) {
363 switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
364 global.times_bullets_switched, 1.0);
365 }
366 else {
367 switch_on_bullet (progress_indicator.bullets_on, progress_indicator.bullets_off,
368 global.times_bullets_switched, 1.0);
369 }
370 }
371
372
373 # Start setting bullets to "on" with translucency
374 # for (index = 0; index <= 5; index++) {
375 # opacity = 0.0;
376 # while (opacity <= 1.0) {
377 # switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
378 # index, opacity);
379 # opacity += 0.1;
380 # }
381 # }
382 }
383
384
385 #-----------------------------------------Label utility functions---------------------
386
387 # label should be either a string or NULL
388 # Images for n lines will be created and returned as items of the
389 # message_label array
390 #
391 fun get_message_label (label, is_fake, is_action_line) {
392 # Debug("Get Label position");
393 local.message_label;
394
395 if (is_fake)
396 # Create a fake label so as to get the y coordinate of
397 # a standard-length label.
398 local.message_image = ImageToTintedText ("This is a fake message");
399 else
400 local.message_image = (is_action_line) && ImageToActionText (label) || ImageToTintedText (label);
401
402 message_label.width = message_image.GetWidth ();
403 message_label.height = message_image.GetHeight ();
404
405 # Center the line horizontally
406 message_label.x = Window.GetX () + Window.GetWidth () / 2 - message_label.width / 2;
407
408 message_label.y = top_of_the_text;
409
410 # Put the 2nd line below the fsck line
411 if (is_action_line) {
412 local.fsck_label.y = message_label.y + (first_line_height + first_line_height / 2);
413 message_label.y = local.fsck_label.y + (first_line_height * 2);
414 }
415
416 # Debug("action label x = " + message_label.x + " y = " + message_label.y );
417
418 # message_debug = "msg_x = " + message_label.x + " msg_y = " + message_label.y +
419 # "msg_width = " + message_label.width + " msg_height = " +
420 # message_label.height + " message = " + label;
421 # Debug(message_debug);
422
423 return message_label;
424
425 }
426
427 # Create an fsck label and/or get its position
428 fun get_fsck_label (label, is_fake) {
429 # Debug("Get Label position");
430 local.fsck_label = global.progress_label;
431
432 if (is_fake)
433 fsck_label.image = ImageToTintedText ("This is a fake message");
434 else
435 fsck_label.image = ImageToTintedText (label);
436
437 fsck_label.width = fsck_label.image.GetWidth ();
438 fsck_label.height = fsck_label.image.GetHeight ();
439
440 # Centre the label horizontally
441 fsck_label.x = Window.GetX () + Window.GetWidth () / 2 - fsck_label.width / 2;
442
443 local.first_label = get_message_label (label, 1, 0);
444
445 # Place the label below the 1st message line
446 fsck_label.y = local.first_label.y + local.first_label.height + (local.first_label.height / 2);
447
448 # message_debug = "msg_x = " + fsck_label.x + " msg_y = " + fsck_label.y +
449 # "msg_width = " + fsck_label.width + " msg_height = " +
450 # fsck_label.height + " message = " + label;
451 # Debug(message_debug);
452
453 return fsck_label;
454 }
455
456 #-----------------------------------------Message stuff --------------------------------
457 #
458
459 # Set up a message label
460 #
461 # NOTE: this is called when doing something like 'plymouth message "hello world"'
462 #
463 fun setup_message (message_text, x, y, z, index) {
464 # Debug("Message setup");
465 global.message_notification[index].image = (index) && ImageToActionText (message_text) || ImageToTintedText (message_text);
466
467 # Set up the text message, if any
468 message_notification[index].x = x;
469 message_notification[index].y = y;
470 message_notification[index].z = z;
471
472 message_notification[index].sprite = Sprite ();
473 message_notification[index].sprite.SetImage (message_notification[index].image);
474 message_notification[index].sprite.SetX (message_notification[index].x);
475 message_notification[index].sprite.SetY (message_notification[index].y);
476 message_notification[index].sprite.SetZ (message_notification[index].z);
477
478 }
479
480 fun show_message (index) {
481 if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(1);
482 }
483
484 fun hide_message (index) {
485 if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(0);
486 }
487
488
489
490
491 # the callback function is called when new message should be displayed.
492 # First arg is message to display.
493 fun message_callback (message)
494 {
495 # Debug("Message callback");
496 is_fake = 0;
497 if (!message || (message == "")) is_fake = 1;
498
499 local.substring = "keys:";
500
501 # Look for the "keys:" prefix
502 local.keys = StringString(message, local.substring);
503
504 local.is_action_line = (keys != NULL);
505 #Debug("keys " + local.keys + " substring length = " + StringLength(local.substring));
506
507 # Get the message without the "keys:" prefix
508 if (keys != NULL)
509 message = StringCopy (message, keys + StringLength(local.substring), NULL);
510
511 # Get the message without the "fsckd-cancel-msg" prefix as we don't support i18n
512 substring = "fsckd-cancel-msg:";
513 keys = StringString(message, substring);
514 if (keys != NULL)
515 message = StringCopy(message, keys + StringLength(substring), NULL);
516
517 local.label.is_fake = is_fake;
518 label = get_message_label(message, is_fake, is_action_line);
519 label.z = 10000;
520
521 setup_message (message, label.x, label.y, label.z, is_action_line);
522 if (prompt_active && local.is_action_line)
523 hide_message (is_action_line);
524 else
525 show_message (is_action_line);
526
527 }
528
529
530 #-----------------------------------------Display Password stuff -----------------------
531 #
532
533 fun password_dialogue_setup (message_label) {
534 # Debug("Password dialog setup");
535
536 local.entry;
537 local.bullet_image;
538
539 bullet_image = Image (password_dot_filename);
540 entry.image = Image (password_field_filename);
541
542 # Hide the normal labels
543 prompt_active = 1;
544 if (message_notification[1].sprite) hide_message (1);
545
546 # Set the prompt label
547 label = get_message_label(message_label, 0, 1);
548 label.z = 10000;
549
550 setup_message (message_label, label.x, label.y, label.z, 2);
551 show_message (2);
552
553 # Set up the text entry which contains the bullets
554 entry.sprite = Sprite ();
555 entry.sprite.SetImage (entry.image);
556
557 # Centre the box horizontally
558 entry.x = Window.GetX () + Window.GetWidth () / 2 - entry.image.GetWidth () / 2;
559
560 # Put the entry below the second label.
561 entry.y = message_notification[2].y + label.height;
562
563 #Debug ("entry x = " + entry.x + ", y = " + entry.y);
564 entry.z = 10000;
565 entry.sprite.SetX (entry.x);
566 entry.sprite.SetY (entry.y);
567 entry.sprite.SetZ (entry.z);
568
569 global.password_dialogue = local;
570 }
571
572 fun password_dialogue_opacity (opacity) {
573 # Debug("Password dialog opacity");
574 global.password_dialogue.opacity = opacity;
575 local = global.password_dialogue;
576
577 # You can make the box translucent with a float
578 # entry.sprite.SetOpacity (0.3);
579 entry.sprite.SetOpacity (opacity);
580 label.sprite.SetOpacity (opacity);
581
582 if (bullets) {
583 for (index = 0; bullets[index]; index++) {
584 bullets[index].sprite.SetOpacity (opacity);
585 }
586 }
587 }
588
589
590 # The callback function is called when the display should display a password dialogue.
591 # First arg is prompt string, the second is the number of bullets.
592 fun display_password_callback (prompt, bullets) {
593 # Debug("Password dialog setup");
594
595 global.status = "password";
596 if (!global.password_dialogue) password_dialogue_setup(prompt);
597 password_dialogue_opacity (1);
598 bullet_width = password_dialogue.bullet_image.GetWidth();
599 bullet_y = password_dialogue.entry.y +
600 password_dialogue.entry.image.GetHeight () / 2 -
601 password_dialogue.bullet_image.GetHeight () / 2;
602 margin = bullet_width;
603 spaces = Math.Int( (password_dialogue.entry.image.GetWidth () - (margin * 2)) / (bullet_width / 2 ) );
604 #Debug ("spaces = " + spaces + ", bullets = " + bullets);
605 bullets_area.width = margin + spaces * (bullet_width / 2);
606 bullets_area.x = Window.GetX () + Window.GetWidth () / 2 - bullets_area.width / 2;
607 #DebugBottom ("pwd_entry x = " + password_dialogue.entry.x + ", bullets_area.x = " + bullets_area.x + ", bullets_area.width = " + bullets_area.width);
608 if (bullets > spaces)
609 bullets = spaces;
610 for (index = 0; password_dialogue.bullets[index] || index < bullets; index++){
611 if (!password_dialogue.bullets[index]) {
612 password_dialogue.bullets[index].sprite = Sprite ();
613 password_dialogue.bullets[index].sprite.SetImage (password_dialogue.bullet_image);
614 password_dialogue.bullets[index].x = bullets_area.x + # password_dialogue.entry.x + margin +
615 index * bullet_width / 2;
616 password_dialogue.bullets[index].sprite.SetX (password_dialogue.bullets[index].x);
617 password_dialogue.bullets[index].y = bullet_y;
618 password_dialogue.bullets[index].sprite.SetY (password_dialogue.bullets[index].y);
619 password_dialogue.bullets[index].z = password_dialogue.entry.z + 1;
620 password_dialogue.bullets[index].sprite.SetZ (password_dialogue.bullets[index].z);
621 }
622
623 password_dialogue.bullets[index].sprite.SetOpacity (0);
624
625 if (index < bullets) {
626 password_dialogue.bullets[index].sprite.SetOpacity (1);
627 }
628 }
629 }
630
631 Plymouth.SetDisplayPasswordFunction (display_password_callback);
632
633 Plymouth.SetMessageFunction (message_callback);
634
635 Plymouth.SetBootProgressFunction (animate_progress_indicator);
636
637 # Plymouth.SetBootProgressFunction: the callback function is called with two numbers, the progress (between 0 and 1) and the time spent booting so far
638 # Plymouth.SetRootMountedFunction: the callback function is called when a new root is mounted
639 # Plymouth.SetKeyboardInputFunction: the callback function is called with a string containing a new character entered on the keyboard
640
641 #----------------------------------------- FSCK Counter --------------------------------
642
643 # Initialise the counter
644 fun init_fsck_count () {
645 # The number of fsck checks in this cycle
646 global.counter.total = 0;
647 # The number of fsck checks already performed + the current one
648 global.counter.current = 1;
649 # The previous fsck
650 global.counter.last = 0;
651 }
652
653 # Increase the total counter
654 fun increase_fsck_count () {
655 global.counter.total++;
656 }
657
658 fun increase_current_fsck_count () {
659 global.counter.last = global.counter.current++;
660 }
661
662 # Clear the counter
663 fun clear_fsck_count () {
664 global.counter = NULL;
665 init_fsck_count ();
666 }
667
668 #----------------------------------------- Progress Label ------------------------------
669
670
671 # Change the opacity level of a progress label
672 #
673 # opacity = 1 -> show
674 # opacity = 0 -> hide
675 # opacity = 0.3 (or any other float) -> translucent
676 #
677 fun set_progress_label_opacity (opacity) {
678 # the label
679 progress_label.sprite.SetOpacity (opacity);
680
681 # Make the slot available again when hiding the bar
682 # So that another bar can take its place
683 if (opacity == 0) {
684 progress_label.is_available = 1;
685 progress_label.device = "";
686 }
687 }
688
689 # Set up a new Progress Bar
690 #
691 # TODO: Make it possible to reuse (rather than recreate) a bar
692 # if .is_available = 1. Ideally this would just reset the
693 # label, the associated
694 # device and the image size of the sprite.
695
696 fun init_progress_label (device, status_string) {
697 # Make the slot unavailable
698 global.progress_label.is_available = 0;
699 progress_label.progress = 0;
700 progress_label.device = device;
701 progress_label.status_string = status_string;
702 }
703
704 # See if the progress label is keeping track of the fsck
705 # of "device"
706 #
707 fun device_has_progress_label (device) {
708 #DebugBottom ("label device = " + progress_label.device + " checking device " + device);
709 return (progress_label.device == device);
710 }
711
712 # Update the Progress bar which corresponds to index
713 #
714 fun update_progress_label (progress) {
715 # If progress is NULL then we just refresh the label.
716 # This happens when only counter.total has changed.
717 if (progress != NULL) {
718 progress_label.progress = progress;
719
720 #Debug("device " + progress_label.device + " progress " + progress);
721
722 # If progress >= 100% hide the label and make it available again
723 if (progress >= 100) {
724 set_progress_label_opacity (0);
725
726 # See if we any other fsck check is complete
727 # and, if so, hide the progress bars and the labels
728 on_fsck_completed ();
729
730 return 0;
731 }
732 }
733 # Update progress label here
734 #
735 # FIXME: the queue logic from this theme should really be moved into mountall
736 # instead of using string replacement to deal with localised strings.
737 label = StringReplace (progress_label.status_string[0], "%1$d", global.counter.current);
738 label = StringReplace (label, "%2$d", global.counter.total);
739 label = StringReplace (label, "%3$d", progress_label.progress);
740 label = StringReplace (label, "%%", "%");
741
742 progress_label = get_fsck_label (label, 0);
743 #progress_label.progress = progress;
744
745 progress_label.sprite = Sprite (progress_label.image);
746
747 # Set up the bar
748 progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
749
750 set_progress_label_opacity (1);
751
752 }
753
754 # Refresh the label so as to update counters
755 fun refresh_progress_label () {
756 update_progress_label (NULL);
757 }
758
759 #----------------------------------------- FSCK Queue ----------------------------------
760
761 # Initialise the fsck queue
762 fun init_queue () {
763 global.fsck_queue[0].device;
764 global.fsck_queue[0].progress;
765 global.fsck_queue.counter = 0;
766 global.fsck_queue.biggest_item = 0;
767 }
768
769 fun clear_queue () {
770 global.fsck_queue = NULL;
771 init_queue ();
772 }
773
774 # Return either the device index in the queue or -1
775 fun queue_look_up_by_device (device) {
776 for (i=0; i <= fsck_queue.biggest_item; i++) {
777 if ((fsck_queue[i]) && (fsck_queue[i].device == device))
778 return i;
779 }
780 return -1;
781 }
782
783 # Keep track of an fsck process in the queue
784 fun add_fsck_to_queue (device, progress) {
785 # Look for an empty slot in the queue
786 for (i=0; global.fsck_queue[i].device; i++) {
787 continue;
788 }
789 local.index = i;
790
791 # Set device and progress
792 global.fsck_queue[local.index].device = device;
793 global.fsck_queue[local.index].progress = progress;
794
795 # Increase the queue counter
796 global.fsck_queue.counter++;
797
798 # Update the max index of the array for iterations
799 if (local.index > global.fsck_queue.biggest_item)
800 global.fsck_queue.biggest_item = local.index;
801
802 #DebugMedium ("Adding " + device + " at " + local.index);
803 }
804
805 fun is_queue_empty () {
806 return (fsck_queue.counter == 0);
807 }
808
809 fun is_progress_label_available () {
810 return (progress_label.is_available == 1);
811 }
812
813
814 # This should cover the case in which the fsck checks in
815 # the queue are completed before the ones showed in the
816 # progress label
817 fun on_queued_fsck_completed () {
818 if (!is_queue_empty ())
819 return;
820
821 # Hide the extra label, if any
822 #if (progress_bar.extra_label.sprite)
823 # progress_bar.extra_label.sprite.SetOpacity(0);
824 }
825
826 fun remove_fsck_from_queue (index) {
827 # Free memory which was previously allocated for
828 # device and progress
829 global.fsck_queue[index].device = NULL;
830 global.fsck_queue[index].progress = NULL;
831
832 # Decrease the queue counter
833 global.fsck_queue.counter--;
834
835 # See if there are other processes in the queue
836 # if not, clear the extra_label
837 on_queued_fsck_completed ();
838 }
839
840 fun on_fsck_completed () {
841 # We have moved on to tracking the next fsck
842 increase_current_fsck_count ();
843
844 if (!is_progress_label_available ())
845 return;
846
847 if (!is_queue_empty ())
848 return;
849
850 # Hide the progress label
851 if (progress_label.sprite)
852 progress_label.sprite.SetOpacity (0);
853
854 # Clear the queue
855 clear_queue ();
856
857 # Clear the fsck counter
858 clear_fsck_count ();
859 }
860
861 # Update an fsck process that we keep track of in the queue
862 fun update_progress_in_queue (index, device, progress) {
863 # If the fsck is complete, remove it from the queue
864 if (progress >= 100) {
865 remove_fsck_from_queue (index);
866 on_queued_fsck_completed ();
867 return;
868 }
869
870 global.fsck_queue[index].device = device;
871 global.fsck_queue[index].progress = progress;
872
873 }
874
875 # TODO: Move it to some function
876 # Create an empty queue
877 #init_queue ();
878
879
880 #----------------------------------------- FSCK Functions ------------------------------
881
882
883 # Either add a new bar for fsck checks or update an existing bar
884 #
885 # NOTE: no more than "progress_bar.max_number" bars are allowed
886 #
887 fun fsck_check (device, progress, status_string) {
888
889 # The 1st time this will take place
890 if (!global.progress_label) {
891 # Increase the fsck counter
892 increase_fsck_count ();
893
894 # Set up a new label for the check
895 init_progress_label (device, status_string);
896 update_progress_label (progress);
897
898 return;
899 }
900
901
902 if (device_has_progress_label (device)) {
903 # Update the progress of the existing label
904 update_progress_label (progress);
905 }
906 else {
907 # See if there's already a slot in the queue for the device
908 local.queue_device_index = queue_look_up_by_device(device);
909
910 # See if the progress_label is available
911 if (progress_label.is_available) {
912
913 # local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter;
914 # Debug(local.my_string);
915
916
917 # If the fsck check for the device was in the queue, then
918 # remove it from the queue
919 if (local.queue_device_index >= 0) {
920 remove_fsck_from_queue (index);
921 }
922 else {
923 # Increase the fsck counter
924 increase_fsck_count ();
925 }
926
927 # local.my_string += local.message;
928 #Debug("setting new label for device " + device + " progress " + progress);
929
930 # Set up a new label for the check
931 init_progress_label (device, status_string);
932 update_progress_label (progress);
933
934 }
935 # If the progress_label is not available
936 else {
937
938 # If the fsck check for the device is already in the queue
939 # just update its progress in the queue
940 if (local.queue_device_index >= 0) {
941 #DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device);
942 update_progress_in_queue (local.queue_device_index, device, progress);
943 }
944 # Otherwise add the check to the queue
945 else {
946 #DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index);
947 add_fsck_to_queue (device, progress);
948
949 # Increase the fsck counter
950 increase_fsck_count ();
951
952 refresh_progress_label ();
953 }
954
955 }
956 }
957
958 # if (!is_queue_empty ()) {
959 # DebugBottom("Extra label for "+ device);
960 #}
961 # else {
962 # DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter);
963 # }
964 }
965
966
967 #-----------------------------------------Update Status stuff --------------------------
968 #
969 # The update_status_callback is what we can use to pass plymouth whatever we want so
970 # as to make use of features which are available only in this program (as opposed to
971 # being available for any theme for the script plugin).
972 #
973 # Example:
974 #
975 # Thanks to the current implementation, some scripts can call "plymouth --update=fsck:sda1:40"
976 # and this program will know that 1) we're performing and fsck check, 2) we're checking sda1,
977 # 3) the program should set the label progress to 40%
978 #
979 # Other features can be easily added by parsing the string that we pass plymouth with "--update"
980 #
981 fun update_status_callback (status) {
982 # Debug(status);
983 if (!status) return;
984
985 string_it = 0;
986 update_strings[string_it] = "";
987
988 for (i=0; (String(status).CharAt(i) != ""); i++) {
989 local.temp_char = String(status).CharAt(i);
990 if (temp_char != ":")
991 update_strings[string_it] += temp_char;
992 else
993 update_strings[++string_it] = "";
994 }
995
996 # my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
997 # Debug(my_string);
998 # Let's assume that we're dealing with these strings fsck:sda1:40
999 if ((string_it >= 2) && (update_strings[0] == "fsck")) {
1000
1001 device = update_strings[1];
1002 progress = update_strings[2];
1003 status_string[0] = update_strings[3]; # "Checking disk %1$d of %2$d (%3$d %% complete)"
1004 if (!status_string[0])
1005 status_string[0] = "Checking disk %1$d of %2$d (%3$d %% complete)";
1006
1007 if ((device != "") && (progress != "")) {
1008 progress = StringToInteger (progress);
1009
1010 # Make sure that the fsck_queue is initialised
1011 if (!global.fsck_queue)
1012 init_queue ();
1013
1014 # Make sure that the fsck counter is initialised
1015 if (!global.counter)
1016 init_fsck_count ();
1017
1018 # if (!global.progress_bar.extra_label.sprite)
1019 # create_extra_fsck_label ();
1020
1021 # Keep track of the fsck check
1022 fsck_check (device, progress, status_string);
1023 }
1024
1025 }
1026
1027 # systemd-fsckd pass fsckd:<number_devices>:<progress>:<l10n_string>
1028 if (update_strings[0] == "fsckd") {
1029 number_devices = StringToInteger(update_strings[1]);
1030
1031 if (number_devices > 0) {
1032 label = update_strings[3];
1033
1034 progress_label = get_fsck_label (label, 0);
1035 progress_label.sprite = Sprite (progress_label.image);
1036 progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
1037 progress_label.sprite.SetOpacity (1);
1038 } else {
1039 if (progress_label.sprite)
1040 progress_label.sprite.SetOpacity (0);
1041 }
1042 }
1043
1044 }
1045 Plymouth.SetUpdateStatusFunction (update_status_callback);
1046
1047 #-----------------------------------------Display Question stuff -----------------------
1048 #
1049 # TODO: Implement this if needed
1050 #
1051 # The callback function is called when the display should display a question dialogue.
1052 # First arg is prompt string, the second is the entry contents.
1053 #fun display_question_callback (prompt_string, entry_contents)
1054 #{
1055 # time++;
1056 #}
1057 #
1058 #Plymouth.SetDisplayQuestionFunction (display_question_callback);
1059
1060 #-----------------------------------------Refresh stuff --------------------------------
1061 #
1062 # Calling Plymouth.SetRefreshFunction with a function will set that function to be
1063 # called up to 50 times every second, e.g.
1064 #
1065 # NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
1066 # the screen correctly
1067 #
1068 fun refresh_callback ()
1069 {
1070 draw_logo ();
1071 }
1072 Plymouth.SetRefreshFunction (refresh_callback);
1073
1074
1075 #-----------------------------------------Display Normal stuff -----------------------
1076 #
1077 # The callback function is called when the display should return to normal
1078 fun display_normal_callback ()
1079 {
1080 global.status = "normal";
1081 if (global.password_dialogue) {
1082 password_dialogue_opacity (0);
1083 global.password_dialogue = NULL;
1084 if (message_notification[2].sprite) hide_message(2);
1085 prompt_active = 0;
1086 }
1087
1088 if (message_notification[1].sprite) show_message (1);
1089
1090
1091 }
1092
1093 Plymouth.SetDisplayNormalFunction (display_normal_callback);
1094
1095
1096 #----------------------------------------- Quit --------------------------------
1097
1098 # TODO: Maybe we should also hide any other dialog
1099 # Show the logo and make the progress indicator look full when on exit
1100 fun quit_callback ()
1101 {
1102 logo.sprite.SetOpacity (1);
1103 switch_on_bullets ();
1104 }
1105
1106 Plymouth.SetQuitFunction(quit_callback);