~viking.redwolf/ubuntu/oneiric/lubuntu-artwork/lubuntu-artwork-fix-877293

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne
  • Date: 2010-02-16 03:02:04 UTC
  • Revision ID: james.westby@ubuntu.com-20100216030204-ddqpqkyf96k8j30l
Tags: 0.4
* debian/links: Add symlink to jpg wallpaper file for backward compatibility.
* debian/control : Add a plymouth theme binary.
* debian/*.install & *.links: Reorganize with the new binary.
* debian/rules: Install in debian/tmp and use dh_install for installation.
* debian/lubuntu-plymouth-theme.postinst & postrm: Set lubuntu-logo as
  default plymouth settings, and reset it to ubuntu-logo after removal.
* Switch to a Lubuntu custom theme, made by Rafael Laguna.
 - Add a lubuntu-logo plymouth theme, based on the ubuntu-logo.
 - Add a custom logo-banner.png, lubuntu-logo.png and panel wallpaper.
 - Add new wallpaper.
 - Add a custom lxdm theme.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  lubuntu-logo.script - boot splash plugin
 
2
# based on ubuntu-logo.script  
 
3
 
4
#  Copyright (C) 2009 Canonical Ltd.
 
5
 
6
#  This program is free software; you can redistribute it and/or modify
 
7
#  it under the terms of the GNU General Public License as published by
 
8
#  the Free Software Foundation; either version 2, or (at your option)
 
9
#  any later version.
 
10
 
11
#  This program is distributed in the hope that it will be useful,
 
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#  GNU General Public License for more details.
 
15
 
16
#  You should have received a copy of the GNU General Public License
 
17
#  along with this program; if not, write to the Free Software
 
18
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
19
#  02111-1307, USA.
 
20
 
21
#  Written 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
 
28
text_colour.red = 255;
 
29
text_colour.green = 255;
 
30
text_colour.blue = 255;
 
31
 
 
32
debugsprite = Sprite();
 
33
debugsprite_bottom = Sprite();
 
34
debugsprite_medium = Sprite();
 
35
 
 
36
fun ImageToText (text) {
 
37
    image = Image.Text (text, text_colour.red, text_colour.green, text_colour.blue);
 
38
    return image;
 
39
}
 
40
 
 
41
fun Debug(text) {
 
42
    debugsprite.SetImage(ImageToText (text));
 
43
}
 
44
 
 
45
fun DebugBottom(text) {
 
46
    debugsprite_bottom.SetImage(ImageToText (text));
 
47
    debugsprite_bottom.SetPosition(0, (Window.GetHeight (0) - 20), 1);
 
48
}
 
49
 
 
50
fun DebugMedium(text) {
 
51
    debugsprite_medium.SetImage(ImageToText (text));
 
52
    debugsprite_medium.SetPosition(0, (Window.GetHeight (0) - 60), 1);
 
53
}
 
54
 
 
55
Window.SetBackgroundTopColor (0, 0, 0);     # Nice blue on top of the screen fading to
 
56
Window.SetBackgroundBottomColor (0, 0, 0);  # an equally nice brown on the bottom
 
57
 
 
58
screen_width = Window.GetWidth ();
 
59
screen_height = Window.GetHeight ();
 
60
wallpaper_image = Image ("wall_blue_2560x1600.png");
 
61
resized_wallpaper_image = wallpaper_image.Scale (screen_width, screen_height);
 
62
wallpaper_sprite = Sprite (resized_wallpaper_image);
 
63
wallpaper_sprite.SetZ (-10000);
 
64
 
 
65
logo.image = Image ("lubuntu-logo.png");
 
66
 
 
67
logo.sprite = Sprite ();
 
68
logo.sprite.SetImage (logo.image);
 
69
 
 
70
logo.width = logo.image.GetWidth ();
 
71
logo.height = logo.image.GetHeight ();
 
72
logo.x = Window.GetWidth (0)  / 2 - logo.width  / 2;
 
73
logo.y = Window.GetHeight (0) / 2 - logo.height / 2;
 
74
logo.z = 1000;
 
75
logo.sprite.SetX (logo.x);
 
76
# label_area_y = logo_area_y + (*label_height * 2) + 60;
 
77
logo.sprite.SetY (logo.y);
 
78
logo.sprite.SetY (logo.z);
 
79
logo.sprite.SetOpacity (1);
 
80
 
 
81
# Spacing below the logo - in pixels
 
82
logo_spacing = 0;
 
83
 
 
84
message_notification.image = ImageToText ("");
 
85
 
 
86
status = "normal";
 
87
 
 
88
 
 
89
 
 
90
#-----------------------------------------Label utility functions---------------------
 
91
 
 
92
fun get_label_position (label, is_fake) {
 
93
    # Debug("Get Label position");
 
94
    screen_width = Window.GetWidth (0);
 
95
    screen_height = Window.GetHeight (0);
 
96
    local.message_label;
 
97
    
 
98
    if (is_fake) {
 
99
        # Create a fake label so as to get the y coordinate of
 
100
        # a standard-lenght label.
 
101
        # This is useful when prompting without providing a
 
102
        # message
 
103
        local.message_image = ImageToText ("This is a fake message");
 
104
        message_label.width = message_image.GetWidth ();
 
105
        message_label.height = message_image.GetHeight ();
 
106
    }
 
107
    else {
 
108
        local.message_image = ImageToText (label);
 
109
        message_label.width = message_image.GetWidth ();
 
110
        message_label.height = message_image.GetHeight ();
 
111
    }
 
112
    
 
113
    # Centre the label horizontally
 
114
    message_label.x = (screen_width / 2) - (message_label.width / 2);
 
115
    
 
116
    # Place the label below the logo 
 
117
    message_label.y = logo.y + logo.height + logo_spacing; # message_label.height / 2;
 
118
    
 
119
#    message_debug = "msg_x = " + message_label.x + " msg_y = " + message_label.y +
 
120
#                    "msg_width = " + message_label.width + " msg_height = " +
 
121
#                    message_label.height + " message = " + label;
 
122
#    Debug(message_debug);
 
123
    
 
124
    return message_label;
 
125
}
 
126
 
 
127
 
 
128
#-----------------------------------------Display Password stuff -----------------------
 
129
#
 
130
 
 
131
fun password_dialogue_setup(message_label) {
 
132
    # Debug("Password dialog setup");
 
133
    
 
134
    local.box;
 
135
    local.lock;
 
136
    local.entry;
 
137
    local.bullet_image;
 
138
    local.is_fake = 0;
 
139
    
 
140
    bullet_image = Image ("bullet.png");
 
141
    box.image = Image ("box.png");
 
142
    entry.image = Image ("entry.png");
 
143
    lock.image = Image ("lock.png");
 
144
    
 
145
    if (!message_label) is_fake = 1;
 
146
    
 
147
    local.label = get_label_position(message_label, is_fake);
 
148
 
 
149
    label.is_fake = is_fake;
 
150
    
 
151
    # Make sure that the prompt label is placed below the message label
 
152
    # NOTE: here we assume that all labels have the same height.
 
153
    label.y += label.height;
 
154
 
 
155
    # Set up the text message, if any
 
156
    if (!is_fake) {
 
157
        label.z = 10000;
 
158
        label.image = ImageToText (message_label);
 
159
        label.sprite = Sprite ();
 
160
        label.sprite.SetImage (label.image);
 
161
        label.sprite.SetX (label.x);
 
162
        label.sprite.SetY (label.y);
 
163
        label.sprite.SetZ (label.z);
 
164
    }
 
165
    
 
166
    # Set up the box area which contains the text entry and the lock icon
 
167
    box.sprite = Sprite ();
 
168
    box.sprite.SetImage (box.image);
 
169
    # Centre the box horizontally
 
170
    box.x = Window.GetWidth (0)  / 2 - box.image.GetWidth () / 2;
 
171
    # Put the box below the label. Leave the space for 2 labels.
 
172
    box.y = label.y + label.height * 2;
 
173
    box.z = 10000;
 
174
    box.sprite.SetX (box.x);
 
175
    box.sprite.SetY (box.y);
 
176
    box.sprite.SetZ (box.z);
 
177
 
 
178
 
 
179
    # Set up the lock icon
 
180
    lock.sprite = Sprite ();
 
181
    lock.sprite.SetImage (lock.image);
 
182
    lock.x = (Window.GetWidth (0)  / 2) - ((lock.image.GetWidth () + entry.image.GetWidth ()) / 2);
 
183
    lock.y = box.y + (box.image.GetHeight () / 2) - (lock.image.GetHeight () / 2);
 
184
    lock.z = box.z + 1;
 
185
    lock.sprite.SetX (lock.x);
 
186
    lock.sprite.SetY (lock.y);
 
187
    lock.sprite.SetZ (lock.z);
 
188
 
 
189
 
 
190
    # Set up the text entry
 
191
    entry.sprite = Sprite ();
 
192
    entry.sprite.SetImage (entry.image);
 
193
    # FIXME: Maybe we should add some horizontal space between the icon and the entry?
 
194
    entry.x = lock.x + lock.image.GetWidth ();
 
195
    entry.y = box.y + (box.image.GetHeight () / 2) - (entry.image.GetHeight () / 2);    
 
196
    entry.z = lock.z;
 
197
    
 
198
    entry.sprite.SetX (entry.x);
 
199
    entry.sprite.SetY (entry.y);
 
200
    entry.sprite.SetZ (entry.z);
 
201
 
 
202
    
 
203
    global.password_dialogue = local;
 
204
}
 
205
 
 
206
fun password_dialogue_opacity (opacity) {
 
207
    # Debug("Password dialog opacity");
 
208
    global.password_dialogue.opacity = opacity;
 
209
    local = global.password_dialogue;
 
210
 
 
211
    # You can make the box translucent with a float
 
212
    # box.sprite.SetOpacity (0.3);
 
213
    box.sprite.SetOpacity (opacity);
 
214
 
 
215
    lock.sprite.SetOpacity (opacity);
 
216
    entry.sprite.SetOpacity (opacity);
 
217
    if (!label.is_fake) label.sprite.SetOpacity (opacity);
 
218
    
 
219
    for (index = 0; bullet[index]; index++) {
 
220
        bullet[index].sprite.SetOpacity (opacity);
 
221
    }
 
222
}
 
223
 
 
224
 
 
225
# The callback function is called when the display should display a password dialogue.
 
226
# First arg is prompt string, the second is the number of bullets.
 
227
fun display_password_callback (prompt, bullets) {
 
228
    # Debug("Password dialog setup");
 
229
    
 
230
    global.status = "password";
 
231
    if (!global.password_dialogue) password_dialogue_setup(prompt);
 
232
    password_dialogue_opacity (1);
 
233
    for (index = 0; password_dialogue.bullet[index] || index < bullets; index++){
 
234
        if (!password_dialogue.bullet[index]) {
 
235
            password_dialogue.bullet[index].sprite = Sprite ();
 
236
            password_dialogue.bullet[index].sprite.SetImage (password_dialogue.bullet_image);
 
237
            password_dialogue.bullet[index].x = password_dialogue.entry.x +
 
238
                                                index * password_dialogue.bullet_image.GetWidth ();
 
239
            password_dialogue.bullet[index].sprite.SetX (password_dialogue.bullet[index].x);
 
240
            password_dialogue.bullet[index].y = password_dialogue.entry.y +
 
241
                                                password_dialogue.entry.image.GetHeight () / 2 -
 
242
                                                password_dialogue.bullet_image.GetHeight () / 2;
 
243
            password_dialogue.bullet[index].sprite.SetY (password_dialogue.bullet[index].y);
 
244
            password_dialogue.bullet[index].z = password_dialogue.entry.z + 1;
 
245
            password_dialogue.bullet[index].sprite.SetZ (password_dialogue.bullet[index].z);
 
246
        }
 
247
 
 
248
        password_dialogue.bullet[index].sprite.SetOpacity (0);
 
249
 
 
250
        if (index < bullets) {
 
251
            password_dialogue.bullet[index].sprite.SetOpacity (1);
 
252
        }
 
253
    }
 
254
}
 
255
 
 
256
Plymouth.SetDisplayPasswordFunction (display_password_callback); 
 
257
 
 
258
 
 
259
 
 
260
 
 
261
#-----------------------------------------Message stuff --------------------------------
 
262
#
 
263
 
 
264
# Set up a message label
 
265
#
 
266
# NOTE: this is called when doing something like 'plymouth message "hello world"'
 
267
#
 
268
fun setup_message (message_text, x, y, z) {
 
269
    # Debug("Message setup");
 
270
    message_notification.image = ImageToText (message_text);
 
271
 
 
272
    # Set up the text message, if any
 
273
    message_notification.x = x;
 
274
    message_notification.y = y;
 
275
    message_notification.z = z;
 
276
    
 
277
    message_notification.sprite = Sprite ();
 
278
    message_notification.sprite.SetImage (message_notification.image);
 
279
    message_notification.sprite.SetX (message_notification.x);
 
280
    message_notification.sprite.SetY (message_notification.y);
 
281
    message_notification.sprite.SetZ (message_notification.z);
 
282
 
 
283
}
 
284
 
 
285
fun show_message () {
 
286
    if (global.message_notification.sprite) global.message_notification.sprite.SetOpacity(1);
 
287
}
 
288
 
 
289
fun hide_message () {
 
290
    if (global.message_notification.sprite) global.message_notification.sprite.SetOpacity(0);
 
291
}
 
292
 
 
293
 
 
294
# the callback function is called when new message should be displayed.
 
295
# First arg is message to display.
 
296
fun message_callback (message)
 
297
{
 
298
    # Debug("Message callback");
 
299
    is_fake = 0;
 
300
    if (!message || (message == "")) is_fake = 1;
 
301
    
 
302
    local.label.is_fake = is_fake;
 
303
    label = get_label_position(message, is_fake);
 
304
    label.z = 10000;
 
305
    
 
306
    setup_message (message, label.x, label.y, label.z);
 
307
    show_message ();
 
308
 
 
309
}
 
310
Plymouth.SetMessageFunction (message_callback);
 
311
 
 
312
 
 
313
# Plymouth.SetBootProgressFunction: the callback function is called with two numbers, the progress (between 0 and 1) and the time spent booting so far
 
314
# Plymouth.SetRootMountedFunction: the callback function is called when a new root is mounted
 
315
# Plymouth.SetKeyboardInputFunction: the callback function is called with a string containing a new character entered on the keyboard
 
316
 
 
317
#----------------------------------------- FSCK Queue ----------------------------------
 
318
 
 
319
# Initialise the fsck queue
 
320
fun init_queue () {
 
321
    global.fsck_queue[0].device;
 
322
    global.fsck_queue[0].progress;
 
323
    global.fsck_queue.counter = 0;
 
324
    global.fsck_queue.biggest_item = 0;    
 
325
}
 
326
 
 
327
fun clear_queue () {
 
328
    global.fsck_queue = NULL;
 
329
    init_queue ();
 
330
}
 
331
 
 
332
# Return either the device index in the queue or -1
 
333
fun queue_look_up_by_device (device) {
 
334
    for (i=0; i <= fsck_queue.biggest_item; i++) {
 
335
        if ((fsck_queue[i]) && (fsck_queue[i].device == device))
 
336
            return i;
 
337
    }
 
338
    return -1;
 
339
}
 
340
 
 
341
# Keep track of an fsck process in the queue
 
342
fun add_fsck_to_queue (device, progress) {
 
343
    # Look for an empty slot in the queue
 
344
    for (i=0; global.fsck_queue[i].device; i++) {
 
345
        continue;
 
346
    }
 
347
    local.index = i;
 
348
    
 
349
    # Set device and progress
 
350
    global.fsck_queue[local.index].device = device;
 
351
    global.fsck_queue[local.index].progress = progress;
 
352
    
 
353
    # Increase the queue counter
 
354
    global.fsck_queue.counter++;
 
355
    
 
356
    # Update the max index of the array for iterations
 
357
    if (local.index > global.fsck_queue.biggest_item)
 
358
        global.fsck_queue.biggest_item = local.index;
 
359
    
 
360
#    DebugMedium ("Adding " + device + " at " + local.index);
 
361
}
 
362
 
 
363
# This should cover the case in which the fsck checks in
 
364
# the queue are completed before the ones showed in the
 
365
# progress bars
 
366
fun on_queued_fsck_completed () {
 
367
    if (!is_queue_empty ())
 
368
        return;
 
369
    
 
370
    # Hide the extra label, if any
 
371
    if (progress_bar.extra_label.sprite)
 
372
        progress_bar.extra_label.sprite.SetOpacity(0);
 
373
}
 
374
 
 
375
fun remove_fsck_from_queue (index) {
 
376
    # Free memory which was previously allocated for
 
377
    # device and progress
 
378
    global.fsck_queue[index].device = NULL;
 
379
    global.fsck_queue[index].progress = NULL;
 
380
 
 
381
    # Decrease the queue counter
 
382
    global.fsck_queue.counter--;
 
383
    
 
384
    # See if there are other processes in the queue
 
385
    # if not, clear the extra_label
 
386
    on_queued_fsck_completed ();
 
387
}
 
388
 
 
389
fun is_queue_empty () {
 
390
    return (fsck_queue.counter == 0);
 
391
}
 
392
 
 
393
fun on_fsck_completed () {
 
394
    if (!are_bars_empty ())
 
395
        return;
 
396
    
 
397
    if (!is_queue_empty ())
 
398
        return;
 
399
    
 
400
    # Hide all progress bars
 
401
    for (index=0; index < progress_bar.max_number; index++) {
 
402
        set_bar_opacity (index, 0);
 
403
    }
 
404
    
 
405
    # Make sure that the bar counter is 0
 
406
    progress_bar.counter = 0;
 
407
    
 
408
    # Hide the extra label, if any
 
409
    if (progress_bar.extra_label.sprite)
 
410
        progress_bar.extra_label.sprite.SetOpacity(0);
 
411
    
 
412
    # Clear the queue
 
413
    clear_queue ();
 
414
}
 
415
 
 
416
# Update an fsck process that we keep track of in the queue
 
417
fun update_progress_in_queue (index, device, progress) {
 
418
    # If the fsck is complete, remove it from the queue
 
419
    if (progress >= 100) {
 
420
        remove_fsck_from_queue (index);
 
421
        on_queued_fsck_completed ();
 
422
        return;
 
423
    }
 
424
    
 
425
    global.fsck_queue[index].device = device;
 
426
    global.fsck_queue[index].progress = progress;
 
427
    
 
428
}
 
429
 
 
430
# Create an empty queue
 
431
init_queue ();
 
432
 
 
433
#----------------------------------------- Progress Bar --------------------------------
 
434
 
 
435
progress_box.image = Image ("progress_box.png");
 
436
#progress_box.height = progress_box.image.GetHeight ();
 
437
 
 
438
progress_bar.original_image = Image ("progress_bar.png");
 
439
#progress_bar.original_height = progress_bar.original_image.GetHeight ();
 
440
progress_bar.counter = 0;
 
441
progress_bar.global_counter = 0;
 
442
progress_bar.max_number = 3;
 
443
progress_bar.extra_label.message;
 
444
 
 
445
# Prepare empty progress bars
 
446
for (i=0; i < progress_bar.max_number ; i++) {
 
447
    progress_bar[i].is_available = 1;
 
448
    progress_bar[i].progress = 0;
 
449
}
 
450
 
 
451
# See if all progress bars are empty
 
452
fun are_bars_empty () {
 
453
    for (i=0; i < progress_bar.max_number ; i++) {
 
454
        if (progress_bar[i].is_available == 0)
 
455
            return 0;
 
456
    }
 
457
    return 1;
 
458
}
 
459
 
 
460
# Change the opacity level of a progress bar and of its label
 
461
#
 
462
# opacity = 1 -> show
 
463
# opacity = 0 -> hide
 
464
# opacity = 0.3 (or any other float) -> translucent
 
465
#
 
466
fun set_bar_opacity (index, opacity) {
 
467
    # the label
 
468
    if (!progress_bar[index].label.is_fake)
 
469
        progress_bar[index].label.sprite.SetOpacity(opacity);
 
470
    
 
471
    # the bar
 
472
    progress_bar[index].sprite.SetOpacity(opacity);
 
473
    
 
474
    # the box
 
475
    progress_bar[index].box.sprite.SetOpacity(opacity);
 
476
    
 
477
    # Make the slot available again when hiding the bar
 
478
    # So that another bar can take its place
 
479
    if (opacity == 0) {
 
480
        progress_bar[index].is_available = 1;
 
481
        progress_bar[index].device = "";
 
482
        progress_bar.counter--;
 
483
    }
 
484
}
 
485
 
 
486
# Set up a new Progress Bar
 
487
#
 
488
# TODO: Make it possible to reuse (rather than recreate) a bar
 
489
#       if .is_available = 1. Ideally this would just reset the
 
490
#       label, the associated
 
491
#       device and the image size of the sprite.
 
492
fun setup_progress_bar (message, index, device) {
 
493
    # Make the slot unavailable
 
494
    progress_bar[index].is_available = 0;
 
495
    
 
496
    progress_bar.counter++;
 
497
 
 
498
    # Fill the slot
 
499
    progress_bar[index].device = device;
 
500
    progress_bar[index].image = progress_bar.original_image;
 
501
    progress_bar[index].sprite = Sprite();
 
502
    progress_bar[index].sprite.SetImage(progress_bar[index].image);
 
503
 
 
504
    is_fake = 0;
 
505
    if (!message || (message == "")) is_fake = 1;
 
506
    
 
507
    local.label.is_fake = is_fake;
 
508
    label = get_label_position(message, is_fake);
 
509
    label.z = 10000;
 
510
    
 
511
    if (index > 0) {
 
512
        # Put the label of the "nth" bar below the bar of the "nth - 1" bar
 
513
        label.y = progress_bar[index - 1].y + progress_bar.original_image.GetHeight() + progress_bar[index - 1].label.height;
 
514
    }
 
515
    else {
 
516
        # index == 0
 
517
        # Leave some space so that a message can be shown above the label
 
518
        # For example if we wanted to show "Press Q to stop the disk checks"
 
519
        #
 
520
        label.y = label.y + label.height + label.height / 2; # Maybe we should add more space
 
521
    }
 
522
 
 
523
    
 
524
    # Set up the bar
 
525
    progress_bar[index].x = Window.GetWidth (0)  / 2 - progress_bar.original_image.GetWidth () / 2;
 
526
    progress_bar[index].y = label.y + label.height + label.height / 3;
 
527
    progress_bar[index].sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 1);
 
528
    
 
529
    # Set up the message label, if any
 
530
    progress_bar[index].label = label;
 
531
    if (!progress_bar[index].label.is_fake) {
 
532
        local.label_image = ImageToText (message);
 
533
        progress_bar[index].label.sprite = Sprite ();
 
534
        progress_bar[index].label.sprite.SetImage(local.label_image);
 
535
        progress_bar[index].label.sprite.SetPosition(progress_bar[index].label.x, progress_bar[index].label.y, 1);
 
536
    }
 
537
        
 
538
 
 
539
    # Set up the Box which contains the bar
 
540
    progress_bar[index].box.sprite = Sprite(progress_box.image);
 
541
    progress_bar[index].x = Window.GetWidth (0)  / 2 -    progress_box.image.GetWidth ()  / 2;
 
542
    progress_bar[index].y = progress_bar[index].y + (progress_bar.original_image.GetHeight () / 2) - (progress_box.image.GetHeight () / 2) ; 
 
543
    progress_bar[index].box.sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 0);
 
544
 
 
545
}
 
546
 
 
547
# Get the index of the progress bar which keeps track of the fsck
 
548
# of "device"
 
549
#
 
550
fun get_progress_bar_index_from_device (device) {
 
551
    local.device_index = -1;
 
552
    for (index=0; index < progress_bar.max_number; index++) {
 
553
        if (progress_bar[index].device == device) {
 
554
            local.device_index = index;
 
555
            break;
 
556
        }
 
557
    }
 
558
    return device_index;
 
559
}
 
560
 
 
561
# See if a progress bar slot is available and return its index
 
562
#
 
563
fun get_available_progress_bar_index () {
 
564
    local.available_index = -1;
 
565
    for (index=0; index < progress_bar.max_number; index++) {
 
566
        if (progress_bar[index].is_available) {
 
567
            local.available_index = index;
 
568
            break;
 
569
        }
 
570
    }
 
571
    return local.available_index;
 
572
}
 
573
 
 
574
# Update the Progress bar which corresponds to index
 
575
#
 
576
fun update_progress_bar_by_index (index, progress) {
 
577
    progress_bar[index].progress = progress;
 
578
    
 
579
#    Debug(progress);
 
580
    
 
581
    # If progress >= 100% hide the bar and make it available again
 
582
    if (progress >= 100) {
 
583
        set_bar_opacity (index, 0);
 
584
        
 
585
        # See if we any other fsck check is complete
 
586
        # and, if so, hide the progress bars and the labels
 
587
        on_fsck_completed ();
 
588
        
 
589
        return 0;
 
590
    }
 
591
    
 
592
#    progress_new = progress + 1;
 
593
#    multiplied = progress_bar.original_image.GetWidth () * progress;
 
594
#    cur_bar_width = progress_bar[index].image.GetWidth ();
 
595
#    
 
596
#    my_string = "progress+1 = " + progress_new + " original * progress = " + multiplied + " current bar width = " + cur_bar_width;
 
597
#    Debug(my_string);
 
598
 
 
599
    if (progress_bar[index].image.GetWidth () != Math.Int (progress_bar.original_image.GetWidth () / 100 * progress))  {
 
600
        progress_bar[index].image = progress_bar.original_image.Scale(progress_bar.original_image.GetWidth(progress_bar.original_image)
 
601
                                                                          / 100 * progress, progress_bar.original_image.GetHeight());
 
602
        
 
603
        progress_bar[index].sprite.SetImage (progress_bar[index].image);
 
604
        progress_bar[index].sprite.SetPosition(progress_bar[index].x, progress_bar[index].y, 1000);
 
605
    }
 
606
 
 
607
}
 
608
 
 
609
 
 
610
#-----------------------------------------Fsck stuff -----------------------------
 
611
#
 
612
 
 
613
# Create a label which tells users that other fsck checks are running in the
 
614
# background
 
615
#
 
616
# NOTE: the bar is hidden by default. You can make it visible with SetOpacity(1)
 
617
#
 
618
fun create_extra_fsck_label () {
 
619
 
 
620
    message = "Further disk checks are taking place in the background. Please wait...";
 
621
 
 
622
    progress_bar.extra_label = get_label_position(message, 0);
 
623
    
 
624
    # Put the label of below the last bar
 
625
    progress_bar.extra_label.y = progress_bar[progress_bar.max_number - 1].y +
 
626
                                    progress_bar.original_image.GetHeight() +
 
627
                                    progress_bar[progress_bar.max_number - 1].label.height;
 
628
 
 
629
    progress_bar.extra_label.z = 10000;
 
630
    # Set up the message label
 
631
    progress_bar.extra_label_image = ImageToText (message);
 
632
    progress_bar.extra_label.sprite = Sprite ();
 
633
    progress_bar.extra_label.sprite.SetImage(progress_bar.extra_label_image);
 
634
    progress_bar.extra_label.sprite.SetPosition(progress_bar.extra_label.x,
 
635
                                            progress_bar.extra_label.y,
 
636
                                            progress_bar.extra_label.z);
 
637
    
 
638
    # Keep the bar hidden by default
 
639
    progress_bar.extra_label.sprite.SetOpacity(0);
 
640
}
 
641
 
 
642
 
 
643
# Either add a new bar for fsck checks or update an existing bar
 
644
#
 
645
# NOTE: no more than "progress_bar.max_number" bars are allowed
 
646
#
 
647
fun fsck_check (device, progress) {
 
648
    
 
649
    # See if we already have a bar for the device check
 
650
    local.device_index = get_progress_bar_index_from_device (device);
 
651
    
 
652
    if (device_index >= 0) {
 
653
#        Debug("Update the progress of the existing bar");
 
654
        # Update the progress of the existing bar
 
655
        update_progress_bar_by_index (device_index, progress);
 
656
    }
 
657
    else {
 
658
        # See if there's already a slot in the queue for the device
 
659
        local.queue_device_index = queue_look_up_by_device(device);
 
660
 
 
661
        # See if there is an available slot
 
662
        # NOTE: we don't allow more than "progress_bar.max_number" bars
 
663
        if (progress_bar.counter < progress_bar.max_number) {
 
664
            # Get the index for the 1st available slot
 
665
            local.available_index = get_available_progress_bar_index ();
 
666
            
 
667
#            local.my_string = "available index " + local.available_index + " progress_bar counter is " + progress_bar.counter;
 
668
#            Debug(local.my_string);
 
669
            
 
670
            if (local.available_index >= 0) {
 
671
                
 
672
                # If the fsck check for the device was in the queue, then
 
673
                # remove it from the queue
 
674
                if (local.queue_device_index >= 0)
 
675
                    remove_fsck_from_queue (index);
 
676
                
 
677
                # Set up a new label for the check
 
678
                local.message = "Routine check of drive " + device;
 
679
                
 
680
#                local.my_string += local.message;
 
681
#                Debug(local.my_string);
 
682
 
 
683
                # Set up a new bar for the check
 
684
                setup_progress_bar (message, local.available_index, device);
 
685
                update_progress_bar_by_index (local.available_index, progress);
 
686
            }
 
687
            
 
688
        }
 
689
        # If there's no available progress bar slot
 
690
        else {
 
691
            
 
692
            # If the fsck check for the device is already in the queue
 
693
            # just update its progress in the queue
 
694
            if (local.queue_device_index >= 0) {
 
695
#                DebugMedium("Updating queue at " + local.queue_device_index + " for device " + device);
 
696
                update_progress_in_queue (local.queue_device_index, device, progress);
 
697
            }
 
698
            # Otherwise add the check to the queue
 
699
            else {
 
700
#                DebugMedium("Adding device " + device + " to queue at " + local.queue_device_index);
 
701
                add_fsck_to_queue (device, progress);
 
702
            }
 
703
            
 
704
        }
 
705
    }
 
706
    
 
707
    if (!is_queue_empty ()) {
 
708
#        DebugBottom("Extra label for "+ device);
 
709
        # Create a label which tells users that other fsck checks are running in the
 
710
        # background
 
711
        create_extra_fsck_label ();
 
712
        # Make the label visible
 
713
        progress_bar.extra_label.sprite.SetOpacity(1);
 
714
    }
 
715
#    else {
 
716
#        DebugBottom("No extra label for " + device + ". 1st Device in the queue "+ fsck_queue[0].device + " counter = " + global.fsck_queue.counter);
 
717
#    }
 
718
}
 
719
 
 
720
# A temporary replacement for atoi()
 
721
# it makes sense to use it only for
 
722
# numbers up to 100
 
723
fun string_to_integer (str) {
 
724
    int = -1;
 
725
    for (i=0; i<=100; i++) {
 
726
        if (i+"" == str) {
 
727
            int = i;
 
728
            break;
 
729
        }
 
730
    }
 
731
    return int;
 
732
}
 
733
 
 
734
#-----------------------------------------Update Status stuff --------------------------
 
735
#
 
736
# The update_status_callback is what we can use to pass plymouth whatever we want so
 
737
# as to make use of features which are available only in this program (as opposed to
 
738
# being available for any theme for the script plugin).
 
739
#
 
740
# Example:
 
741
#
 
742
#   Thanks to the current implementation, some scripts can call "plymouth --update=fsck:sda1:40"
 
743
#   and this program will know that 1) we're performing and fsck check, 2) we're checking sda1,
 
744
#   3) the program should set the bar progress to 40%
 
745
#
 
746
# Other features can be easily added by parsing the string that we pass plymouth with "--update"
 
747
#
 
748
fun update_status_callback (status) {
 
749
#    Debug(status);
 
750
    if (!status) return;
 
751
    
 
752
    string_it = 0;
 
753
    update_strings[string_it] = "";
 
754
    
 
755
    for (i=0; (String(status).CharAt(i) != ""); i++) {
 
756
        local.temp_char = String(status).CharAt(i);
 
757
        if (temp_char != ":")
 
758
            update_strings[string_it] += temp_char;
 
759
        else
 
760
            update_strings[++string_it] = "";
 
761
    }
 
762
    
 
763
#    my_string = update_strings[0] + " " + update_strings[1] + " " + update_strings[2];
 
764
#    Debug(my_string);
 
765
    # Let's assume that we're dealing with these strings fsck:sda1:40
 
766
    if ((string_it == 2) && (update_strings[0] == "fsck")) {
 
767
        
 
768
        device = update_strings[1];
 
769
        progress = update_strings[2];
 
770
        
 
771
        if ((device != "") && (progress != "")) {
 
772
            progress = string_to_integer (progress);
 
773
        
 
774
            # Make sure that the fsck_queue is initialised
 
775
            if (!global.fsck_queue)
 
776
                init_queue ();
 
777
            
 
778
            if (!global.progress_bar.extra_label.sprite)
 
779
                create_extra_fsck_label ();
 
780
            
 
781
            # Keep track of the fsck check
 
782
            fsck_check (device, progress);
 
783
        }
 
784
        
 
785
    }
 
786
 
 
787
}
 
788
Plymouth.SetUpdateStatusFunction (update_status_callback); 
 
789
 
 
790
 
 
791
 
 
792
#-----------------------------------------Display Question stuff -----------------------
 
793
#
 
794
# TODO: Implement this if needed
 
795
#
 
796
# The callback function is called when the display should display a question dialogue.
 
797
# First arg is prompt string, the second is the entry contents.
 
798
#fun display_question_callback (prompt_string, entry_contents)
 
799
#{
 
800
# time++;
 
801
#}
 
802
#
 
803
#Plymouth.SetDisplayQuestionFunction (display_question_callback); 
 
804
 
 
805
#-----------------------------------------Refresh stuff --------------------------------
 
806
#
 
807
# Calling Plymouth.SetRefreshFunction with a function will set that function to be
 
808
# called up to 50 times every second, e.g.
 
809
#
 
810
# NOTE: if a refresh function is not set, Plymouth doesn't seem to be able to update
 
811
#       the screen correctly
 
812
#
 
813
fun refresh_callback ()
 
814
{
 
815
    logo.sprite.SetX (logo.x);
 
816
    logo.sprite.SetY (logo.y);
 
817
    logo.sprite.SetZ (logo.z);
 
818
    logo.sprite.SetOpacity (1);
 
819
}
 
820
Plymouth.SetRefreshFunction (refresh_callback);
 
821
 
 
822
 
 
823
#-----------------------------------------Display Normal stuff -----------------------
 
824
#
 
825
# The callback function is called when the display should return to normal
 
826
fun display_normal_callback ()
 
827
{
 
828
    global.status = "normal";
 
829
    if (global.password_dialogue) password_dialogue_opacity (0);
 
830
    
 
831
    if (message_notification.sprite) hide_message ();
 
832
}
 
833
 
 
834
Plymouth.SetDisplayNormalFunction (display_normal_callback);
 
835
 
 
836
 
 
837
#----------------------------------------- Quit --------------------------------
 
838
 
 
839
fun quit_callback ()
 
840
{
 
841
    logo.sprite.SetOpacity (1);
 
842
}
 
843
 
 
844
Plymouth.SetQuitFunction(quit_callback);