Debian Codegraph @

ceratopsian-theme/plymouth/ceratopsian.script

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