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