~ubuntu-branches/ubuntu/vivid/ubuntukylin-theme/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/plymouth/themes/ubuntukylin-logo/ubuntukylin-logo.script

  • Committer: Package Import Robot
  • Author(s): zhangchao (work)
  • Date: 2013-03-14 10:28:00 UTC
  • Revision ID: package-import@ubuntu.com-20130314102800-78ehv34yfsw836rd
Tags: 0.4.2
del plymouth-text

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  ubuntukylin-logo.script - boot splash plugin
 
2
 
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)
 
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
# Re-written by Rafael Laguna <rafaellaguna@gmail.com> based from
 
21
#  original by Alberto Milone <alberto.milone@canonical.com>
 
22
#
 
23
#  Based on the example provided with the "script plugin" written by:
 
24
#              Charlie Brej   <cbrej@cs.man.ac.uk>
 
25
 
26
 
 
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;
 
31
 
 
32
# Tinted text #988592
 
33
tinted_text_colour.red = 0.59;
 
34
tinted_text_colour.green = 0.52;
 
35
tinted_text_colour.blue = 0.57;
 
36
 
 
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;
 
41
 
 
42
# Orange - #ff4012 - RGB 255 64 18
 
43
debugsprite = Sprite();
 
44
debugsprite_bottom = Sprite();
 
45
debugsprite_medium = Sprite();
 
46
 
 
47
# are we currently prompting for a password?
 
48
prompt_active = 0;
 
49
 
 
50
# General purpose function to create text
 
51
fun WriteText (text, colour) {
 
52
    image = Image.Text (text, colour.red, colour.green, colour.blue);
 
53
    return image;
 
54
}
 
55
 
 
56
fun ImageToText (text) {
 
57
    image = WriteText (text, text_colour);
 
58
    return image;
 
59
}
 
60
 
 
61
fun ImageToTintedText (text) {
 
62
    image = WriteText (text, tinted_text_colour);
 
63
    return image;
 
64
}
 
65
 
 
66
fun ImageToActionText (text) {
 
67
    image = WriteText (text, action_text_colour);
 
68
    return image;
 
69
}
 
70
 
 
71
fun Debug(text) {
 
72
    debugsprite.SetImage(ImageToText (text));
 
73
}
 
74
 
 
75
fun DebugBottom(text) {
 
76
    debugsprite_bottom.SetImage(ImageToText (text));
 
77
    debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
 
78
}
 
79
 
 
80
fun DebugMedium(text) {
 
81
    debugsprite_medium.SetImage(ImageToText (text));
 
82
    debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 60), 1);
 
83
}
 
84
 
 
85
fun TextYOffset() {
 
86
    local.y;
 
87
    local.text_height;
 
88
    local.min_height;
 
89
 
 
90
    # Put the 1st line below the logo + some spacing 
 
91
    y = logo.y + logo.height + (progress_indicator.bullet_height * 7 ); # + logo_spacing;
 
92
 
 
93
    text_height = first_line_height * 7.5;
 
94
 
 
95
    min_height = Window.GetHeight();
 
96
    if (y + text_height > min_height)
 
97
        y = min_height - text_height;
 
98
 
 
99
    if (y < progress_indicator.y + progress_indicator.height)
 
100
        return progress_indicator.y + progress_indicator.height;
 
101
    return y;
 
102
}
 
103
 
 
104
#------------------------------String functions-------------------------------
 
105
 
 
106
# This is the equivalent for strstr()
 
107
fun StringString(string, substring) {
 
108
    start = 0;
 
109
    while (String(string).CharAt (start)) {
 
110
        walk = 0;
 
111
        while (String(substring).CharAt (walk) == String(string).CharAt (start + walk) ) {
 
112
            walk++;
 
113
            if (!String(substring).CharAt (walk)) return start;
 
114
        }
 
115
        start++;
 
116
    }
 
117
    
 
118
    return NULL;
 
119
}
 
120
 
 
121
fun StringLength (string) {
 
122
    index = 0;
 
123
    while (String(string).CharAt(index)) index++;
 
124
    return index;
 
125
}
 
126
 
 
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);
 
131
    }
 
132
    
 
133
    return local.destination;
 
134
}
 
135
 
 
136
fun StringReplace (source, pattern, replacement) {
 
137
    local.found = StringString(source, pattern);
 
138
    if (local.found == NULL)
 
139
        return source;
 
140
 
 
141
    local.new_string = StringCopy (source, 0, local.found - 1) +
 
142
                       replacement +
 
143
                       StringCopy (source, local.found + StringLength(pattern), NULL);
 
144
 
 
145
    return local.new_string;
 
146
}
 
147
 
 
148
# it makes sense to use it only for
 
149
# numbers up to 100
 
150
fun StringToInteger (str) {
 
151
    int = -1;
 
152
    for (i=0; i<=100; i++) {
 
153
        if (i+"" == str) {
 
154
            int = i;
 
155
            break;
 
156
        }
 
157
    }
 
158
    return int;
 
159
}
 
160
 
 
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
 
166
#
 
167
# New ubuntukylin background 
 
168
# 0.00, 0.09, 0.17
 
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
 
171
 
 
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;
 
179
logo.z = 1000;
 
180
logo.sprite.SetX (logo.x);
 
181
logo.sprite.SetY (logo.y);
 
182
logo.sprite.SetZ (logo.z);
 
183
logo.sprite.SetOpacity (1);
 
184
 
 
185
# Spacing below the logo - in pixels
 
186
logo_spacing = logo.height * 4;
 
187
 
 
188
message_notification[0].image = ImageToTintedText ("");
 
189
message_notification[1].image = ImageToTintedText ("");
 
190
fsck_notification.image = ImageToActionText ("");
 
191
 
 
192
status = "normal";
 
193
 
 
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;
 
203
 
 
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();
 
208
 
 
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
 
211
# a bit if needed.
 
212
top_of_the_text = TextYOffset();
 
213
 
 
214
#-----------------------------------------Logo functions------------------------------
 
215
 
 
216
# Call this when updating the screen
 
217
fun draw_logo () {
 
218
    logo.sprite.SetX (logo.x);
 
219
    logo.sprite.SetY (logo.y);
 
220
    logo.sprite.SetZ (logo.z);
 
221
    logo.sprite.SetOpacity (1);
 
222
}
 
223
 
 
224
 
 
225
#-----------------------------------------Progress Indicator--------------------------
 
226
fun set_progress_indicator () {
 
227
    
 
228
    
 
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;
 
232
    
 
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);
 
240
        
 
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;
 
244
        #   
 
245
        #(index % 2) && DebugMedium (local.debug_medium_string) || DebugBottom (local.debug_medium_string);
 
246
 
 
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);
 
252
 
 
253
        progress_indicator.bullets_on[index].sprite.SetOpacity (0);
 
254
        
 
255
        local.x += progress_indicator.bullet_hspacing;
 
256
    }
 
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);
 
260
}
 
261
 
 
262
 
 
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;
 
270
    
 
271
    # Hide the bullets which are off
 
272
    bullets_off[bullet_number].sprite.SetOpacity (0);
 
273
    
 
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);
 
277
    
 
278
    # Bump the number of times we have switched on bullets
 
279
    global.times_bullets_switched++;
 
280
}
 
281
 
 
282
fun switch_off_bullets () {
 
283
    # Debug("Switching off progress indicator");
 
284
    
 
285
    set_progress_indicator ();
 
286
    global.times_bullets_switched = 0;
 
287
    global.on_off = 1;
 
288
}
 
289
 
 
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;
 
295
 
 
296
    for (index = 0; bullets_on[index]; index++) {
 
297
        switch_on_bullet (bullets_off, bullets_on, index, 1.0);
 
298
    }
 
299
}
 
300
 
 
301
 
 
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 ();
 
307
    }
 
308
 
 
309
#    Debug ("progress = " + progress + ", time = " + time + " times switched = " + global.times_bullets_switched + " on_off " + global.on_off);
 
310
 
 
311
#    if (global.times_bullets_switched == NULL)
 
312
#        global.times_bullets_switched = 5;
 
313
 
 
314
#    if (global.on_off == NULL)
 
315
#        global.on_off = 0;
 
316
 
 
317
    if ((progress - global.progress_time) >= 1.0) {
 
318
        global.progress_time = progress;
 
319
        
 
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;
 
325
        }
 
326
        
 
327
        if (global.on_off) {
 
328
            switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
 
329
                              global.times_bullets_switched, 1.0);
 
330
        }
 
331
        else {
 
332
            switch_on_bullet (progress_indicator.bullets_on, progress_indicator.bullets_off,
 
333
                              global.times_bullets_switched, 1.0);
 
334
        }
 
335
    }
 
336
    
 
337
    
 
338
    # Start setting bullets to "on" with translucency
 
339
#    for (index = 0; index <= 5; index++) {
 
340
#        opacity = 0.0;
 
341
#        while (opacity <= 1.0) {
 
342
#            switch_on_bullet (progress_indicator.bullets_off, progress_indicator.bullets_on,
 
343
#                              index, opacity);
 
344
#            opacity += 0.1;
 
345
#        }
 
346
#    }
 
347
}
 
348
 
 
349
 
 
350
#-----------------------------------------Label utility functions---------------------
 
351
 
 
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
 
355
#
 
356
fun get_message_label (label, is_fake, is_action_line) {
 
357
    # Debug("Get Label position");
 
358
    local.message_label;
 
359
    
 
360
    if (is_fake)
 
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");
 
364
    else
 
365
        local.message_image = (is_action_line) && ImageToActionText (label) || ImageToTintedText (label);
 
366
        
 
367
    message_label.width = message_image.GetWidth ();
 
368
    message_label.height = message_image.GetHeight ();
 
369
 
 
370
    # Center the line horizontally
 
371
    message_label.x = Window.GetX () + Window.GetWidth () / 2 - message_label.width / 2;
 
372
 
 
373
    message_label.y = top_of_the_text;
 
374
 
 
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);
 
379
    }
 
380
 
 
381
    # Debug("action label x = " + message_label.x + " y = " + message_label.y );
 
382
 
 
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);
 
387
    
 
388
    return message_label;
 
389
 
 
390
}
 
391
 
 
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;
 
396
    
 
397
    if (is_fake)
 
398
        fsck_label.image = ImageToTintedText ("This is a fake message");
 
399
    else
 
400
        fsck_label.image = ImageToTintedText (label);
 
401
    
 
402
    fsck_label.width = fsck_label.image.GetWidth ();
 
403
    fsck_label.height = fsck_label.image.GetHeight ();
 
404
    
 
405
    # Centre the label horizontally
 
406
    fsck_label.x = Window.GetX () + Window.GetWidth () / 2 - fsck_label.width / 2;
 
407
    
 
408
    local.first_label = get_message_label (label, 1, 0);
 
409
    
 
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);
 
412
    
 
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);
 
417
    
 
418
    return fsck_label;
 
419
}
 
420
 
 
421
#-----------------------------------------Message stuff --------------------------------
 
422
#
 
423
 
 
424
# Set up a message label
 
425
#
 
426
# NOTE: this is called when doing something like 'plymouth message "hello world"'
 
427
#
 
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);
 
431
 
 
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;
 
436
    
 
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);
 
442
 
 
443
}
 
444
 
 
445
fun show_message (index) {
 
446
    if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(1);
 
447
}
 
448
 
 
449
fun hide_message (index) {
 
450
    if (global.message_notification[index].sprite) global.message_notification[index].sprite.SetOpacity(0);
 
451
}
 
452
 
 
453
 
 
454
 
 
455
 
 
456
# the callback function is called when new message should be displayed.
 
457
# First arg is message to display.
 
458
fun message_callback (message)
 
459
{
 
460
    # Debug("Message callback");
 
461
    is_fake = 0;
 
462
    if (!message || (message == "")) is_fake = 1;
 
463
    
 
464
    local.substring = "keys:";
 
465
    
 
466
    # Look for the "keys:" prefix
 
467
    local.keys = StringString(message, local.substring);
 
468
    
 
469
    local.is_action_line = (keys != NULL);
 
470
    #Debug("keys " + local.keys + " substring length = " + StringLength(local.substring));
 
471
 
 
472
    # Get the message without the "keys:" prefix
 
473
    if (keys != NULL)
 
474
        message = StringCopy (message, keys + StringLength(local.substring), NULL);
 
475
 
 
476
    local.label.is_fake = is_fake;
 
477
    label = get_message_label(message, is_fake, is_action_line);
 
478
    label.z = 10000;
 
479
    
 
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);
 
483
    else
 
484
        show_message (is_action_line);
 
485
 
 
486
}
 
487
 
 
488
 
 
489
#-----------------------------------------Display Password stuff -----------------------
 
490
#
 
491
 
 
492
fun password_dialogue_setup (message_label) {
 
493
    # Debug("Password dialog setup");
 
494
    
 
495
    local.entry;
 
496
    local.bullet_image;
 
497
    
 
498
    bullet_image = Image ("progress_dot_off.png");
 
499
    entry.image = Image ("password_field.png");
 
500
    
 
501
    # Hide the normal labels
 
502
    prompt_active = 1;
 
503
    if (message_notification[1].sprite) hide_message (1);
 
504
    
 
505
    # Set the prompt label
 
506
    label = get_message_label(message_label, 0, 1);
 
507
    label.z = 10000;
 
508
    
 
509
    setup_message (message_label, label.x, label.y, label.z, 2);
 
510
    show_message (2);
 
511
 
 
512
    # Set up the text entry which contains the bullets
 
513
    entry.sprite = Sprite ();
 
514
    entry.sprite.SetImage (entry.image);
 
515
    
 
516
    # Centre the box horizontally
 
517
    entry.x = Window.GetX () + Window.GetWidth () / 2 - entry.image.GetWidth () / 2;
 
518
 
 
519
    # Put the entry below the second label.
 
520
    entry.y = message_notification[2].y + label.height;
 
521
 
 
522
    #Debug ("entry x = " + entry.x + ", y = " + entry.y);
 
523
    entry.z = 10000;
 
524
    entry.sprite.SetX (entry.x);
 
525
    entry.sprite.SetY (entry.y);
 
526
    entry.sprite.SetZ (entry.z);
 
527
 
 
528
    global.password_dialogue = local;
 
529
}
 
530
 
 
531
fun password_dialogue_opacity (opacity) {
 
532
    # Debug("Password dialog opacity");
 
533
    global.password_dialogue.opacity = opacity;
 
534
    local = global.password_dialogue;
 
535
 
 
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);
 
540
    
 
541
    if (bullets) {
 
542
        for (index = 0; bullets[index]; index++) {
 
543
            bullets[index].sprite.SetOpacity (opacity);
 
544
        }
 
545
    }
 
546
}
 
547
 
 
548
 
 
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");
 
553
    
 
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)
 
568
        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);
 
580
        }
 
581
 
 
582
        password_dialogue.bullets[index].sprite.SetOpacity (0);
 
583
 
 
584
        if (index < bullets) {
 
585
            password_dialogue.bullets[index].sprite.SetOpacity (1);
 
586
        }
 
587
    }
 
588
}
 
589
 
 
590
Plymouth.SetDisplayPasswordFunction (display_password_callback); 
 
591
 
 
592
Plymouth.SetMessageFunction (message_callback);
 
593
 
 
594
Plymouth.SetBootProgressFunction (animate_progress_indicator);
 
595
 
 
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
 
599
 
 
600
#----------------------------------------- FSCK Counter --------------------------------
 
601
 
 
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;
 
608
    # The previous fsck
 
609
    global.counter.last = 0;
 
610
}
 
611
 
 
612
# Increase the total counter
 
613
fun increase_fsck_count () {
 
614
    global.counter.total++;
 
615
}
 
616
 
 
617
fun increase_current_fsck_count () {
 
618
    global.counter.last = global.counter.current++;
 
619
}
 
620
 
 
621
# Clear the counter
 
622
fun clear_fsck_count () {
 
623
    global.counter = NULL;
 
624
    init_fsck_count ();
 
625
}
 
626
 
 
627
#----------------------------------------- Progress Label ------------------------------
 
628
 
 
629
 
 
630
# Change the opacity level of a progress label
 
631
#
 
632
# opacity = 1 -> show
 
633
# opacity = 0 -> hide
 
634
# opacity = 0.3 (or any other float) -> translucent
 
635
#
 
636
fun set_progress_label_opacity (opacity) {
 
637
    # the label
 
638
    progress_label.sprite.SetOpacity (opacity);
 
639
    
 
640
    # Make the slot available again when hiding the bar
 
641
    # So that another bar can take its place
 
642
    if (opacity == 0) {
 
643
        progress_label.is_available = 1;
 
644
        progress_label.device = "";
 
645
    }
 
646
}
 
647
 
 
648
# Set up a new Progress Bar
 
649
#
 
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.
 
654
 
 
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;
 
661
}
 
662
 
 
663
# See if the progress label is keeping track of the fsck
 
664
# of "device"
 
665
#
 
666
fun device_has_progress_label (device) {
 
667
    #DebugBottom ("label device = " + progress_label.device + " checking device " + device);
 
668
    return (progress_label.device == device);
 
669
}
 
670
 
 
671
# Update the Progress bar which corresponds to index
 
672
#
 
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;
 
678
    
 
679
        #Debug("device " + progress_label.device + " progress " + progress);
 
680
    
 
681
        # If progress >= 100% hide the label and make it available again
 
682
        if (progress >= 100) {
 
683
            set_progress_label_opacity (0);
 
684
        
 
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 ();
 
688
        
 
689
            return 0;
 
690
        }
 
691
    }    
 
692
    # Update progress label here
 
693
    #
 
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, "%%",  "%");
 
700
 
 
701
    progress_label = get_fsck_label (label, 0);
 
702
    #progress_label.progress = progress;
 
703
 
 
704
    progress_label.sprite = Sprite (progress_label.image);
 
705
    
 
706
    # Set up the bar
 
707
    progress_label.sprite.SetPosition(progress_label.x, progress_label.y, 1);
 
708
 
 
709
    set_progress_label_opacity (1);
 
710
 
 
711
}
 
712
 
 
713
# Refresh the label so as to update counters
 
714
fun refresh_progress_label () {
 
715
    update_progress_label (NULL);
 
716
}
 
717
 
 
718
#----------------------------------------- FSCK Queue ----------------------------------
 
719
 
 
720
# Initialise the fsck queue
 
721
fun init_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;    
 
726
}
 
727
 
 
728
fun clear_queue () {
 
729
    global.fsck_queue = NULL;
 
730
    init_queue ();
 
731
}
 
732
 
 
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))
 
737
            return i;
 
738
    }
 
739
    return -1;
 
740
}
 
741
 
 
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++) {
 
746
        continue;
 
747
    }
 
748
    local.index = i;
 
749
    
 
750
    # Set device and progress
 
751
    global.fsck_queue[local.index].device = device;
 
752
    global.fsck_queue[local.index].progress = progress;
 
753
    
 
754
    # Increase the queue counter
 
755
    global.fsck_queue.counter++;
 
756
    
 
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;
 
760
    
 
761
    #DebugMedium ("Adding " + device + " at " + local.index);
 
762
}
 
763
 
 
764
fun is_queue_empty () {
 
765
    return (fsck_queue.counter == 0);
 
766
}
 
767
 
 
768
fun is_progress_label_available () {
 
769
    return (progress_label.is_available == 1);
 
770
}
 
771
 
 
772
 
 
773
# This should cover the case in which the fsck checks in
 
774
# the queue are completed before the ones showed in the
 
775
# progress label
 
776
fun on_queued_fsck_completed () {
 
777
    if (!is_queue_empty ())
 
778
        return;
 
779
    
 
780
    # Hide the extra label, if any
 
781
    #if (progress_bar.extra_label.sprite)
 
782
    #    progress_bar.extra_label.sprite.SetOpacity(0);
 
783
}
 
784
 
 
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;
 
790
 
 
791
    # Decrease the queue counter
 
792
    global.fsck_queue.counter--;
 
793
    
 
794
    # See if there are other processes in the queue
 
795
    # if not, clear the extra_label
 
796
    on_queued_fsck_completed ();
 
797
}
 
798
 
 
799
fun on_fsck_completed () {
 
800
    # We have moved on to tracking the next fsck
 
801
    increase_current_fsck_count ();
 
802
 
 
803
    if (!is_progress_label_available ())
 
804
        return;
 
805
    
 
806
    if (!is_queue_empty ())
 
807
        return;
 
808
    
 
809
    # Hide the progress label
 
810
    if (progress_label.sprite)
 
811
        progress_label.sprite.SetOpacity (0);
 
812
    
 
813
    # Clear the queue
 
814
    clear_queue ();
 
815
 
 
816
    # Clear the fsck counter
 
817
    clear_fsck_count ();
 
818
}
 
819
 
 
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 ();
 
826
        return;
 
827
    }
 
828
    
 
829
    global.fsck_queue[index].device = device;
 
830
    global.fsck_queue[index].progress = progress;
 
831
    
 
832
}
 
833
 
 
834
# TODO: Move it to some function
 
835
# Create an empty queue
 
836
#init_queue ();
 
837
 
 
838
 
 
839
#----------------------------------------- FSCK Functions ------------------------------
 
840
 
 
841
 
 
842
# Either add a new bar for fsck checks or update an existing bar
 
843
#
 
844
# NOTE: no more than "progress_bar.max_number" bars are allowed
 
845
#
 
846
fun fsck_check (device, progress, status_string) {
 
847
 
 
848
    # The 1st time this will take place
 
849
    if (!global.progress_label) {
 
850
        # Increase the fsck counter
 
851
        increase_fsck_count ();
 
852
 
 
853
        # Set up a new label for the check
 
854
        init_progress_label (device, status_string);
 
855
        update_progress_label (progress);
 
856
 
 
857
        return;
 
858
    }
 
859
 
 
860
    
 
861
    if (device_has_progress_label (device)) {
 
862
        # Update the progress of the existing label
 
863
        update_progress_label (progress);
 
864
    }
 
865
    else {
 
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);
 
868
 
 
869
        # See if the progress_label is available
 
870
        if (progress_label.is_available) {
 
871
            
 
872
#            local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter;
 
873
#            Debug(local.my_string);
 
874
            
 
875
                
 
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);
 
880
            }
 
881
            else {
 
882
                # Increase the fsck counter
 
883
                increase_fsck_count ();
 
884
            }
 
885
            
 
886
#            local.my_string += local.message;
 
887
            #Debug("setting new label for device " + device + " progress " + progress);
 
888
 
 
889
            # Set up a new label for the check
 
890
            init_progress_label (device, status_string);
 
891
            update_progress_label (progress);
 
892
            
 
893
        }
 
894
        # If the progress_label is not available
 
895
        else {
 
896
            
 
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);
 
902
            }
 
903
            # Otherwise add the check to the queue
 
904
            else {
 
905
                #DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index);
 
906
                add_fsck_to_queue (device, progress);
 
907
 
 
908
                # Increase the fsck counter
 
909
                increase_fsck_count ();
 
910
 
 
911
                refresh_progress_label ();
 
912
            }
 
913
            
 
914
        }
 
915
    }
 
916
    
 
917
#    if (!is_queue_empty ()) {
 
918
#        DebugBottom("Extra label for "+ device);
 
919
    #}
 
920
#    else {
 
921
#        DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter);
 
922
#    }
 
923
}
 
924
 
 
925
 
 
926
#-----------------------------------------Update Status stuff --------------------------
 
927
#
 
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).
 
931
#
 
932
# Example:
 
933
#
 
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%
 
937
#
 
938
# Other features can be easily added by parsing the string that we pass plymouth with "--update"
 
939
#
 
940
fun update_status_callback (status) {
 
941
#    Debug(status);
 
942
    if (!status) return;
 
943
    
 
944
    string_it = 0;
 
945
    update_strings[string_it] = "";
 
946
    
 
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;
 
951
        else
 
952
            update_strings[++string_it] = "";
 
953
    }
 
954
    
 
955
#    my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
 
956
#    Debug(my_string);
 
957
    # Let's assume that we're dealing with these strings fsck:sda1:40
 
958
    if ((string_it >= 2) && (update_strings[0] == "fsck")) {
 
959
        
 
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)";
 
965
        
 
966
        if ((device != "") && (progress != "")) {
 
967
            progress = StringToInteger (progress);
 
968
        
 
969
            # Make sure that the fsck_queue is initialised
 
970
            if (!global.fsck_queue)
 
971
                init_queue ();
 
972
 
 
973
            # Make sure that the fsck counter is initialised
 
974
            if (!global.counter)
 
975
                init_fsck_count ();
 
976
 
 
977
#            if (!global.progress_bar.extra_label.sprite)
 
978
#                create_extra_fsck_label ();
 
979
            
 
980
            # Keep track of the fsck check
 
981
            fsck_check (device, progress, status_string);
 
982
        }
 
983
        
 
984
    }
 
985
 
 
986
}
 
987
Plymouth.SetUpdateStatusFunction (update_status_callback); 
 
988
 
 
989
#-----------------------------------------Display Question stuff -----------------------
 
990
#
 
991
# TODO: Implement this if needed
 
992
#
 
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)
 
996
#{
 
997
# time++;
 
998
#}
 
999
#
 
1000
#Plymouth.SetDisplayQuestionFunction (display_question_callback); 
 
1001
 
 
1002
#-----------------------------------------Refresh stuff --------------------------------
 
1003
#
 
1004
# Calling Plymouth.SetRefreshFunction with a function will set that function to be
 
1005
# called up to 50 times every second, e.g.
 
1006
#
 
1007
# NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
 
1008
#       the screen correctly
 
1009
#
 
1010
fun refresh_callback ()
 
1011
{
 
1012
    draw_logo ();
 
1013
}
 
1014
Plymouth.SetRefreshFunction (refresh_callback);
 
1015
 
 
1016
 
 
1017
#-----------------------------------------Display Normal stuff -----------------------
 
1018
#
 
1019
# The callback function is called when the display should return to normal
 
1020
fun display_normal_callback ()
 
1021
{
 
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);
 
1027
        prompt_active = 0;
 
1028
    }
 
1029
    
 
1030
    if (message_notification[1].sprite) show_message (1);
 
1031
    
 
1032
    
 
1033
}
 
1034
 
 
1035
Plymouth.SetDisplayNormalFunction (display_normal_callback);
 
1036
 
 
1037
 
 
1038
#----------------------------------------- Quit --------------------------------
 
1039
 
 
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 ()
 
1043
{
 
1044
    logo.sprite.SetOpacity (1);
 
1045
    switch_on_bullets (); 
 
1046
}
 
1047
 
 
1048
Plymouth.SetQuitFunction(quit_callback);