1
# ubuntukylin-logo.script - boot splash plugin
3
# Copyright (C) 2009 Canonical Ltd.
4
# Copyright (C) 2013 National University of Defense Technology(NUDT) & Kylin Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2, or (at your option)
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
# Re-written by Rafael Laguna <rafaellaguna@gmail.com> based from
21
# original by Alberto Milone <alberto.milone@canonical.com>
23
# Based on the example provided with the "script plugin" written by:
24
# Charlie Brej <cbrej@cs.man.ac.uk>
27
# Set the text colour in (rgb / 256)
28
text_colour.red = 1.0;
29
text_colour.green = 1.0;
30
text_colour.blue = 1.0;
33
tinted_text_colour.red = 0.59;
34
tinted_text_colour.green = 0.52;
35
tinted_text_colour.blue = 0.57;
37
# Action Text - #ffffff - RGB 255 255 255
38
action_text_colour.red = 1.0;
39
action_text_colour.green = 1.0;
40
action_text_colour.blue = 1.0;
42
# Orange - #ff4012 - RGB 255 64 18
43
debugsprite = Sprite();
44
debugsprite_bottom = Sprite();
45
debugsprite_medium = Sprite();
47
# are we currently prompting for a password?
50
# General purpose function to create text
51
fun WriteText (text, colour) {
52
image = Image.Text (text, colour.red, colour.green, colour.blue);
56
fun ImageToText (text) {
57
image = WriteText (text, text_colour);
61
fun ImageToTintedText (text) {
62
image = WriteText (text, tinted_text_colour);
66
fun ImageToActionText (text) {
67
image = WriteText (text, action_text_colour);
72
debugsprite.SetImage(ImageToText (text));
75
fun DebugBottom(text) {
76
debugsprite_bottom.SetImage(ImageToText (text));
77
debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
80
fun DebugMedium(text) {
81
debugsprite_medium.SetImage(ImageToText (text));
82
debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 60), 1);
90
# Put the 1st line below the logo + some spacing
91
y = logo.y + logo.height + (progress_indicator.bullet_height * 7 ); # + logo_spacing;
93
text_height = first_line_height * 7.5;
95
min_height = Window.GetHeight();
96
if (y + text_height > min_height)
97
y = min_height - text_height;
99
if (y < progress_indicator.y + progress_indicator.height)
100
return progress_indicator.y + progress_indicator.height;
104
#------------------------------String functions-------------------------------
106
# This is the equivalent for strstr()
107
fun StringString(string, substring) {
109
while (String(string).CharAt (start)) {
111
while (String(substring).CharAt (walk) == String(string).CharAt (start + walk) ) {
113
if (!String(substring).CharAt (walk)) return start;
121
fun StringLength (string) {
123
while (String(string).CharAt(index)) index++;
127
fun StringCopy (source, beginning, end) {
128
local.destination = "";
129
for (index = beginning; ( ( (end == NULL) || (index <= end) ) && (String(source).CharAt(index)) ); index++) {
130
local.destination += String(source).CharAt(index);
133
return local.destination;
136
fun StringReplace (source, pattern, replacement) {
137
local.found = StringString(source, pattern);
138
if (local.found == NULL)
141
local.new_string = StringCopy (source, 0, local.found - 1) +
143
StringCopy (source, local.found + StringLength(pattern), NULL);
145
return local.new_string;
148
# it makes sense to use it only for
150
fun StringToInteger (str) {
152
for (i=0; i<=100; i++) {
161
#-----------------------------------------------------------------------------
162
# Previous background colour
163
# #300a24 --> 0.19, 0.04, 0.14
164
# New background colour
165
# #2c001e --> 0.16, 0.00, 0.12
167
# New ubuntukylin background
169
Window.SetBackgroundTopColor (0.26, 0.13, 0.07); # Nice colour on top of the screen fading to
170
Window.SetBackgroundBottomColor (0.26, 0.13, 0.07); # an equally nice colour on the bottom
172
logo.image = Image ("ubuntukylin_logo.png"); # "special://logo" is a special keyword which finds the logo image
173
logo.sprite = Sprite ();
174
logo.sprite.SetImage (logo.image);
175
logo.width = logo.image.GetWidth ();
176
logo.height = logo.image.GetHeight ();
177
logo.x = Window.GetX () + Window.GetWidth () / 2 - logo.width / 2;
178
logo.y = Window.GetY () + Window.GetHeight () / 2 - logo.height;
180
logo.sprite.SetX (logo.x);
181
logo.sprite.SetY (logo.y);
182
logo.sprite.SetZ (logo.z);
183
logo.sprite.SetOpacity (1);
185
# Spacing below the logo - in pixels
186
logo_spacing = logo.height * 4;
188
message_notification[0].image = ImageToTintedText ("");
189
message_notification[1].image = ImageToTintedText ("");
190
fsck_notification.image = ImageToActionText ("");
194
progress_indicator.bullet_off = Image ("progress_dot_off.png");
195
progress_indicator.bullet_on = Image ("progress_dot_on.png");
196
progress_indicator.bullet_width = progress_indicator.bullet_off.GetWidth ();
197
progress_indicator.bullet_height = progress_indicator.bullet_off.GetHeight ();
198
progress_indicator.bullet_hspacing = progress_indicator.bullet_width * 1.1;
199
progress_indicator.width = progress_indicator.bullet_width * 5;
200
progress_indicator.height = progress_indicator.bullet_height;
201
progress_indicator.y = logo.y + logo.height + (logo.height / 4);
202
progress_indicator.x = Window.GetX () + Window.GetWidth () / 2 - progress_indicator.width / 2; # logo.x + 26;
204
# use a fixed string with ascending and descending stems to calibrate the
205
# bounding box for the first message, so the messages below don't move up
206
# and down according to *their* height.
207
first_line_height = ImageToTintedText ("AfpqtM").GetHeight();
209
# if the user has a 640x480 or 800x600 display, we can't quite fit everything
210
# (including passphrase prompts) with the target spacing, so scoot the text up
212
top_of_the_text = TextYOffset();
214
#-----------------------------------------Logo functions------------------------------
216
# Call this when updating the screen
218
logo.sprite.SetX (logo.x);
219
logo.sprite.SetY (logo.y);
220
logo.sprite.SetZ (logo.z);
221
logo.sprite.SetOpacity (1);
225
#-----------------------------------------Progress Indicator--------------------------
226
fun set_progress_indicator () {
229
# Here we assume that we can store half bullets on each half of the screen
230
# together with some spacing
231
local.x = progress_indicator.x;
233
for (index = 0; index <= 4; index++) {
234
# Set the "off" bullets
235
progress_indicator.bullets_off[index].sprite = Sprite (progress_indicator.bullet_off);
236
progress_indicator.bullets_off[index].sprite.SetPosition (local.x, progress_indicator.y, 1000);
237
progress_indicator.bullets_off[index].x = local.x;
238
progress_indicator.bullets_off[index].y = progress_indicator.y;
239
progress_indicator.bullets_off[index].sprite.SetOpacity (1);
241
#local.debug_medium_string = "Progress indicator " + index + ": x = " + progress_indicator.bullets_off[index].x +
242
# ", y = " + progress_indicator.bullets_off[index].y + ", logo width = " + logo.width +
243
# ", logo height = " + logo.height + " " + screen_width + " " + screen_height;
245
#(index % 2) && DebugMedium (local.debug_medium_string) || DebugBottom (local.debug_medium_string);
247
# Set the "on" bullets on top of the "off" bullets and make them transparent
248
progress_indicator.bullets_on[index].sprite = Sprite (progress_indicator.bullet_on);
249
progress_indicator.bullets_on[index].x = progress_indicator.bullets_off[index].x;
250
progress_indicator.bullets_on[index].y = progress_indicator.bullets_off[index].y;
251
progress_indicator.bullets_on[index].sprite.SetPosition (progress_indicator.bullets_on[index].x, progress_indicator.bullets_on[index].y, 10000);
253
progress_indicator.bullets_on[index].sprite.SetOpacity (0);
255
local.x += progress_indicator.bullet_hspacing;
257
#local.debug_string = "Progress indicator: x1 = " + progress_indicator.x + ", x2 = " + local.x + ", y = " + progress_indicator.y +
258
# ", x logo = " + logo.x + ", y logo = " + logo.y + ", indicator width = " + progress_indicator.width;
259
#Debug(progress_indicator.bullets_off[0].x);
263
# We have 2 bullets, one on top of the other:
264
# The white one is on top of the red one and the former should
265
# slowly fade so as to get a nice transition effect.
266
fun switch_on_bullet (bullets_off, bullets_on, bullet_number, opacity) {
267
local.x = bullets_on[bullet_number].x;
268
local.y = bullets_on[bullet_number].y;
269
local.z = bullets_on[bullet_number].z;
271
# Hide the bullets which are off
272
bullets_off[bullet_number].sprite.SetOpacity (0);
274
# Show the bullets which are on
275
bullets_on[bullet_number].sprite.SetPosition (local.x, local.y, local.z);
276
bullets_on[bullet_number].sprite.SetOpacity (opacity);
278
# Bump the number of times we have switched on bullets
279
global.times_bullets_switched++;
282
fun switch_off_bullets () {
283
# Debug("Switching off progress indicator");
285
set_progress_indicator ();
286
global.times_bullets_switched = 0;
290
# This is something that we can call when we exit
291
fun switch_on_bullets () {
292
# Debug("Switching off progress indicator");
293
if (!global.progress_indicator.bullets_on) set_progress_indicator ();
294
local = global.progress_indicator;
296
for (index = 0; bullets_on[index]; index++) {
297
switch_on_bullet (bullets_off, bullets_on, index, 1.0);
302
# Implement in boot progress callback
303
fun animate_progress_indicator (progress, time) {
304
if (global.progress_time == NULL) {
305
global.progress_time = progress; #time;
306
switch_off_bullets ();
309
# Debug ("progress = " + progress + ", time = " + time + " times switched = " + global.times_bullets_switched + " on_off " + global.on_off);
311
# if (global.times_bullets_switched == NULL)
312
# global.times_bullets_switched = 5;
314
# if (global.on_off == NULL)
317
if ((progress - global.progress_time) >= 1.0) {
318
global.progress_time = progress;
320
if (global.times_bullets_switched == 5) {
321
# Change which bullets are switched on
322
# and which ones are switched off
323
global.on_off = !global.on_off;
324
global.times_bullets_switched = 0;
328
switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
329
global.times_bullets_switched, 1.0);
332
switch_on_bullet (progress_indicator.bullets_on, progress_indicator.bullets_off,
333
global.times_bullets_switched, 1.0);
338
# Start setting bullets to "on" with translucency
339
# for (index = 0; index <= 5; index++) {
341
# while (opacity <= 1.0) {
342
# switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
350
#-----------------------------------------Label utility functions---------------------
352
# label should be either a string or NULL
353
# Images for n lines will be created and returned as items of the
354
# message_label array
356
fun get_message_label (label, is_fake, is_action_line) {
357
# Debug("Get Label position");
361
# Create a fake label so as to get the y coordinate of
362
# a standard-length label.
363
local.message_image = ImageToTintedText ("This is a fake message");
365
local.message_image = (is_action_line) && ImageToActionText (label) || ImageToTintedText (label);
367
message_label.width = message_image.GetWidth ();
368
message_label.height = message_image.GetHeight ();
370
# Center the line horizontally
371
message_label.x = Window.GetX () + Window.GetWidth () / 2 - message_label.width / 2;
373
message_label.y = top_of_the_text;
375
# Put the 2nd line below the fsck line
376
if (is_action_line) {
377
local.fsck_label.y = message_label.y + (first_line_height + first_line_height / 2);
378
message_label.y = local.fsck_label.y + (first_line_height * 2);
381
# Debug("action label x = " + message_label.x + " y = " + message_label.y );
383
# message_debug = "msg_x = " + message_label.x + " msg_y = " + message_label.y +
384
# "msg_width = " + message_label.width + " msg_height = " +
385
# message_label.height + " message = " + label;
386
# Debug(message_debug);
388
return message_label;
392
# Create an fsck label and/or get its position
393
fun get_fsck_label (label, is_fake) {
394
# Debug("Get Label position");
395
local.fsck_label = global.progress_label;
398
fsck_label.image = ImageToTintedText ("This is a fake message");
400
fsck_label.image = ImageToTintedText (label);
402
fsck_label.width = fsck_label.image.GetWidth ();
403
fsck_label.height = fsck_label.image.GetHeight ();
405
# Centre the label horizontally
406
fsck_label.x = Window.GetX () + Window.GetWidth () / 2 - fsck_label.width / 2;
408
local.first_label = get_message_label (label, 1, 0);
410
# Place the label below the 1st message line
411
fsck_label.y = local.first_label.y + local.first_label.height + (local.first_label.height / 2);
413
# message_debug = "msg_x = " + fsck_label.x + " msg_y = " + fsck_label.y +
414
# "msg_width = " + fsck_label.width + " msg_height = " +
415
# fsck_label.height + " message = " + label;
416
# Debug(message_debug);
421
#-----------------------------------------Message stuff --------------------------------
424
# Set up a message label
426
# NOTE: this is called when doing something like 'plymouth message "hello world"'
428
fun setup_message (message_text, x, y, z, index) {
429
# Debug("Message setup");
430
global.message_notification[index].image = (index) && ImageToActionText (message_text) || ImageToTintedText (message_text);
432
# Set up the text message, if any
433
message_notification[index].x = x;
434
message_notification[index].y = y;
435
message_notification[index].z = z;
437
message_notification[index].sprite = Sprite ();
438
message_notification[index].sprite.SetImage (message_notification[index].image);
439
message_notification[index].sprite.SetX (message_notification[index].x);
440
message_notification[index].sprite.SetY (message_notification[index].y);
441
message_notification[index].sprite.SetZ (message_notification[index].z);
445
fun show_message (index) {
446
if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(1);
449
fun hide_message (index) {
450
if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(0);
456
# the callback function is called when new message should be displayed.
457
# First arg is message to display.
458
fun message_callback (message)
460
# Debug("Message callback");
462
if (!message || (message == "")) is_fake = 1;
464
local.substring = "keys:";
466
# Look for the "keys:" prefix
467
local.keys = StringString(message, local.substring);
469
local.is_action_line = (keys != NULL);
470
#Debug("keys " + local.keys + " substring length = " + StringLength(local.substring));
472
# Get the message without the "keys:" prefix
474
message = StringCopy (message, keys + StringLength(local.substring), NULL);
476
local.label.is_fake = is_fake;
477
label = get_message_label(message, is_fake, is_action_line);
480
setup_message (message, label.x, label.y, label.z, is_action_line);
481
if (prompt_active && local.is_action_line)
482
hide_message (is_action_line);
484
show_message (is_action_line);
489
#-----------------------------------------Display Password stuff -----------------------
492
fun password_dialogue_setup (message_label) {
493
# Debug("Password dialog setup");
498
bullet_image = Image ("progress_dot_off.png");
499
entry.image = Image ("password_field.png");
501
# Hide the normal labels
503
if (message_notification[1].sprite) hide_message (1);
505
# Set the prompt label
506
label = get_message_label(message_label, 0, 1);
509
setup_message (message_label, label.x, label.y, label.z, 2);
512
# Set up the text entry which contains the bullets
513
entry.sprite = Sprite ();
514
entry.sprite.SetImage (entry.image);
516
# Centre the box horizontally
517
entry.x = Window.GetX () + Window.GetWidth () / 2 - entry.image.GetWidth () / 2;
519
# Put the entry below the second label.
520
entry.y = message_notification[2].y + label.height;
522
#Debug ("entry x = " + entry.x + ", y = " + entry.y);
524
entry.sprite.SetX (entry.x);
525
entry.sprite.SetY (entry.y);
526
entry.sprite.SetZ (entry.z);
528
global.password_dialogue = local;
531
fun password_dialogue_opacity (opacity) {
532
# Debug("Password dialog opacity");
533
global.password_dialogue.opacity = opacity;
534
local = global.password_dialogue;
536
# You can make the box translucent with a float
537
# entry.sprite.SetOpacity (0.3);
538
entry.sprite.SetOpacity (opacity);
539
label.sprite.SetOpacity (opacity);
542
for (index = 0; bullets[index]; index++) {
543
bullets[index].sprite.SetOpacity (opacity);
549
# The callback function is called when the display should display a password dialogue.
550
# First arg is prompt string, the second is the number of bullets.
551
fun display_password_callback (prompt, bullets) {
552
# Debug("Password dialog setup");
554
global.status = "password";
555
if (!global.password_dialogue) password_dialogue_setup(prompt);
556
password_dialogue_opacity (1);
557
bullet_width = password_dialogue.bullet_image.GetWidth();
558
bullet_y = password_dialogue.entry.y +
559
password_dialogue.entry.image.GetHeight () / 2 -
560
password_dialogue.bullet_image.GetHeight () / 2;
561
margin = bullet_width;
562
spaces = Math.Int( (password_dialogue.entry.image.GetWidth () - (margin * 2)) / (bullet_width / 2 ) );
563
#Debug ("spaces = " + spaces + ", bullets = " + bullets);
564
bullets_area.width = margin + spaces * (bullet_width / 2);
565
bullets_area.x = Window.GetX () + Window.GetWidth () / 2 - bullets_area.width / 2;
566
#DebugBottom ("pwd_entry x = " + password_dialogue.entry.x + ", bullets_area.x = " + bullets_area.x + ", bullets_area.width = " + bullets_area.width);
567
if (bullets > spaces)
569
for (index = 0; password_dialogue.bullets[index] || index < bullets; index++){
570
if (!password_dialogue.bullets[index]) {
571
password_dialogue.bullets[index].sprite = Sprite ();
572
password_dialogue.bullets[index].sprite.SetImage (password_dialogue.bullet_image);
573
password_dialogue.bullets[index].x = bullets_area.x + # password_dialogue.entry.x + margin +
574
index * bullet_width / 2;
575
password_dialogue.bullets[index].sprite.SetX (password_dialogue.bullets[index].x);
576
password_dialogue.bullets[index].y = bullet_y;
577
password_dialogue.bullets[index].sprite.SetY (password_dialogue.bullets[index].y);
578
password_dialogue.bullets[index].z = password_dialogue.entry.z + 1;
579
password_dialogue.bullets[index].sprite.SetZ (password_dialogue.bullets[index].z);
582
password_dialogue.bullets[index].sprite.SetOpacity (0);
584
if (index < bullets) {
585
password_dialogue.bullets[index].sprite.SetOpacity (1);
590
Plymouth.SetDisplayPasswordFunction (display_password_callback);
592
Plymouth.SetMessageFunction (message_callback);
594
Plymouth.SetBootProgressFunction (animate_progress_indicator);
596
# Plymouth.SetBootProgressFunction: the callback function is called with two numbers, the progress (between 0 and 1) and the time spent booting so far
597
# Plymouth.SetRootMountedFunction: the callback function is called when a new root is mounted
598
# Plymouth.SetKeyboardInputFunction: the callback function is called with a string containing a new character entered on the keyboard
600
#----------------------------------------- FSCK Counter --------------------------------
602
# Initialise the counter
603
fun init_fsck_count () {
604
# The number of fsck checks in this cycle
605
global.counter.total = 0;
606
# The number of fsck checks already performed + the current one
607
global.counter.current = 1;
609
global.counter.last = 0;
612
# Increase the total counter
613
fun increase_fsck_count () {
614
global.counter.total++;
617
fun increase_current_fsck_count () {
618
global.counter.last = global.counter.current++;
622
fun clear_fsck_count () {
623
global.counter = NULL;
627
#----------------------------------------- Progress Label ------------------------------
630
# Change the opacity level of a progress label
632
# opacity = 1 -> show
633
# opacity = 0 -> hide
634
# opacity = 0.3 (or any other float) -> translucent
636
fun set_progress_label_opacity (opacity) {
638
progress_label.sprite.SetOpacity (opacity);
640
# Make the slot available again when hiding the bar
641
# So that another bar can take its place
643
progress_label.is_available = 1;
644
progress_label.device = "";
648
# Set up a new Progress Bar
650
# TODO: Make it possible to reuse (rather than recreate) a bar
651
# if .is_available = 1. Ideally this would just reset the
652
# label, the associated
653
# device and the image size of the sprite.
655
fun init_progress_label (device, status_string) {
656
# Make the slot unavailable
657
global.progress_label.is_available = 0;
658
progress_label.progress = 0;
659
progress_label.device = device;
660
progress_label.status_string = status_string;
663
# See if the progress label is keeping track of the fsck
666
fun device_has_progress_label (device) {
667
#DebugBottom ("label device = " + progress_label.device + " checking device " + device);
668
return (progress_label.device == device);
671
# Update the Progress bar which corresponds to index
673
fun update_progress_label (progress) {
674
# If progress is NULL then we just refresh the label.
675
# This happens when only counter.total has changed.
676
if (progress != NULL) {
677
progress_label.progress = progress;
679
#Debug("device " + progress_label.device + " progress " + progress);
681
# If progress >= 100% hide the label and make it available again
682
if (progress >= 100) {
683
set_progress_label_opacity (0);
685
# See if we any other fsck check is complete
686
# and, if so, hide the progress bars and the labels
687
on_fsck_completed ();
692
# Update progress label here
694
# FIXME: the queue logic from this theme should really be moved into mountall
695
# instead of using string replacement to deal with localised strings.
696
label = StringReplace (progress_label.status_string[0], "%1$d", global.counter.current);
697
label = StringReplace (label, "%2$d", global.counter.total);
698
label = StringReplace (label, "%3$d", progress_label.progress);
699
label = StringReplace (label, "%%", "%");
701
progress_label = get_fsck_label (label, 0);
702
#progress_label.progress = progress;
704
progress_label.sprite = Sprite (progress_label.image);
707
progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
709
set_progress_label_opacity (1);
713
# Refresh the label so as to update counters
714
fun refresh_progress_label () {
715
update_progress_label (NULL);
718
#----------------------------------------- FSCK Queue ----------------------------------
720
# Initialise the fsck queue
722
global.fsck_queue[0].device;
723
global.fsck_queue[0].progress;
724
global.fsck_queue.counter = 0;
725
global.fsck_queue.biggest_item = 0;
729
global.fsck_queue = NULL;
733
# Return either the device index in the queue or -1
734
fun queue_look_up_by_device (device) {
735
for (i=0; i <= fsck_queue.biggest_item; i++) {
736
if ((fsck_queue[i]) && (fsck_queue[i].device == device))
742
# Keep track of an fsck process in the queue
743
fun add_fsck_to_queue (device, progress) {
744
# Look for an empty slot in the queue
745
for (i=0; global.fsck_queue[i].device; i++) {
750
# Set device and progress
751
global.fsck_queue[local.index].device = device;
752
global.fsck_queue[local.index].progress = progress;
754
# Increase the queue counter
755
global.fsck_queue.counter++;
757
# Update the max index of the array for iterations
758
if (local.index > global.fsck_queue.biggest_item)
759
global.fsck_queue.biggest_item = local.index;
761
#DebugMedium ("Adding " + device + " at " + local.index);
764
fun is_queue_empty () {
765
return (fsck_queue.counter == 0);
768
fun is_progress_label_available () {
769
return (progress_label.is_available == 1);
773
# This should cover the case in which the fsck checks in
774
# the queue are completed before the ones showed in the
776
fun on_queued_fsck_completed () {
777
if (!is_queue_empty ())
780
# Hide the extra label, if any
781
#if (progress_bar.extra_label.sprite)
782
# progress_bar.extra_label.sprite.SetOpacity(0);
785
fun remove_fsck_from_queue (index) {
786
# Free memory which was previously allocated for
787
# device and progress
788
global.fsck_queue[index].device = NULL;
789
global.fsck_queue[index].progress = NULL;
791
# Decrease the queue counter
792
global.fsck_queue.counter--;
794
# See if there are other processes in the queue
795
# if not, clear the extra_label
796
on_queued_fsck_completed ();
799
fun on_fsck_completed () {
800
# We have moved on to tracking the next fsck
801
increase_current_fsck_count ();
803
if (!is_progress_label_available ())
806
if (!is_queue_empty ())
809
# Hide the progress label
810
if (progress_label.sprite)
811
progress_label.sprite.SetOpacity (0);
816
# Clear the fsck counter
820
# Update an fsck process that we keep track of in the queue
821
fun update_progress_in_queue (index, device, progress) {
822
# If the fsck is complete, remove it from the queue
823
if (progress >= 100) {
824
remove_fsck_from_queue (index);
825
on_queued_fsck_completed ();
829
global.fsck_queue[index].device = device;
830
global.fsck_queue[index].progress = progress;
834
# TODO: Move it to some function
835
# Create an empty queue
839
#----------------------------------------- FSCK Functions ------------------------------
842
# Either add a new bar for fsck checks or update an existing bar
844
# NOTE: no more than "progress_bar.max_number" bars are allowed
846
fun fsck_check (device, progress, status_string) {
848
# The 1st time this will take place
849
if (!global.progress_label) {
850
# Increase the fsck counter
851
increase_fsck_count ();
853
# Set up a new label for the check
854
init_progress_label (device, status_string);
855
update_progress_label (progress);
861
if (device_has_progress_label (device)) {
862
# Update the progress of the existing label
863
update_progress_label (progress);
866
# See if there's already a slot in the queue for the device
867
local.queue_device_index = queue_look_up_by_device(device);
869
# See if the progress_label is available
870
if (progress_label.is_available) {
872
# local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter;
873
# Debug(local.my_string);
876
# If the fsck check for the device was in the queue, then
877
# remove it from the queue
878
if (local.queue_device_index >= 0) {
879
remove_fsck_from_queue (index);
882
# Increase the fsck counter
883
increase_fsck_count ();
886
# local.my_string += local.message;
887
#Debug("setting new label for device " + device + " progress " + progress);
889
# Set up a new label for the check
890
init_progress_label (device, status_string);
891
update_progress_label (progress);
894
# If the progress_label is not available
897
# If the fsck check for the device is already in the queue
898
# just update its progress in the queue
899
if (local.queue_device_index >= 0) {
900
#DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device);
901
update_progress_in_queue (local.queue_device_index, device, progress);
903
# Otherwise add the check to the queue
905
#DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index);
906
add_fsck_to_queue (device, progress);
908
# Increase the fsck counter
909
increase_fsck_count ();
911
refresh_progress_label ();
917
# if (!is_queue_empty ()) {
918
# DebugBottom("Extra label for "+ device);
921
# DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter);
926
#-----------------------------------------Update Status stuff --------------------------
928
# The update_status_callback is what we can use to pass plymouth whatever we want so
929
# as to make use of features which are available only in this program (as opposed to
930
# being available for any theme for the script plugin).
934
# Thanks to the current implementation, some scripts can call "plymouth --update=fsck:sda1:40"
935
# and this program will know that 1) we're performing and fsck check, 2) we're checking sda1,
936
# 3) the program should set the label progress to 40%
938
# Other features can be easily added by parsing the string that we pass plymouth with "--update"
940
fun update_status_callback (status) {
945
update_strings[string_it] = "";
947
for (i=0; (String(status).CharAt(i) != ""); i++) {
948
local.temp_char = String(status).CharAt(i);
949
if (temp_char != ":")
950
update_strings[string_it] += temp_char;
952
update_strings[++string_it] = "";
955
# my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
957
# Let's assume that we're dealing with these strings fsck:sda1:40
958
if ((string_it >= 2) && (update_strings[0] == "fsck")) {
960
device = update_strings[1];
961
progress = update_strings[2];
962
status_string[0] = update_strings[3]; # "Checking disk %1$d of %2$d (%3$d %% complete)"
963
if (!status_string[0])
964
status_string[0] = "Checking disk %1$d of %2$d (%3$d %% complete)";
966
if ((device != "") && (progress != "")) {
967
progress = StringToInteger (progress);
969
# Make sure that the fsck_queue is initialised
970
if (!global.fsck_queue)
973
# Make sure that the fsck counter is initialised
977
# if (!global.progress_bar.extra_label.sprite)
978
# create_extra_fsck_label ();
980
# Keep track of the fsck check
981
fsck_check (device, progress, status_string);
987
Plymouth.SetUpdateStatusFunction (update_status_callback);
989
#-----------------------------------------Display Question stuff -----------------------
991
# TODO: Implement this if needed
993
# The callback function is called when the display should display a question dialogue.
994
# First arg is prompt string, the second is the entry contents.
995
#fun display_question_callback (prompt_string, entry_contents)
1000
#Plymouth.SetDisplayQuestionFunction (display_question_callback);
1002
#-----------------------------------------Refresh stuff --------------------------------
1004
# Calling Plymouth.SetRefreshFunction with a function will set that function to be
1005
# called up to 50 times every second, e.g.
1007
# NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
1008
# the screen correctly
1010
fun refresh_callback ()
1014
Plymouth.SetRefreshFunction (refresh_callback);
1017
#-----------------------------------------Display Normal stuff -----------------------
1019
# The callback function is called when the display should return to normal
1020
fun display_normal_callback ()
1022
global.status = "normal";
1023
if (global.password_dialogue) {
1024
password_dialogue_opacity (0);
1025
global.password_dialogue = NULL;
1026
if (message_notification[2].sprite) hide_message(2);
1030
if (message_notification[1].sprite) show_message (1);
1035
Plymouth.SetDisplayNormalFunction (display_normal_callback);
1038
#----------------------------------------- Quit --------------------------------
1040
# TODO: Maybe we should also hide any other dialog
1041
# Show the logo and make the progress indicator look full when on exit
1042
fun quit_callback ()
1044
logo.sprite.SetOpacity (1);
1045
switch_on_bullets ();
1048
Plymouth.SetQuitFunction(quit_callback);