Debian Codegraph @

futureprototype-theme/plymouth/futureprototype.script

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