Debian Codegraph @

homeworld-theme/plymouth/homeworld.script

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