fork download
  1. /**************************************************************************
  2. *
  3. * Copyright (C) 2011 The Xubuntu Community
  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 3 of the License, or
  9. * (at your option) 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, see <http://w...content-available-to-author-only...u.org/licenses/>.
  18. *
  19. * Written by: Mad Nick <dr.madnick@gmail.com>
  20. *
  21. **************************************************************************/
  22.  
  23. /*
  24. * Related to the screen */
  25.  
  26. screen_width = Window.GetWidth(0);
  27. screen_height = Window.GetHeight(0);
  28.  
  29. /**/
  30.  
  31. /*
  32. * Images, check bits per pixel
  33. * and load images accordingly */
  34.  
  35. background_image = Image("xubuntu-greybird.png");
  36. passw_dialog_input_image = Image("passw-dialog.png");
  37. bullet_image = Image("test.png");
  38.  
  39. bpp = Window.GetBitsPerPixel();
  40.  
  41. if (bpp == 4) {
  42.  
  43. logotype_image = Image("logo_16bit.png");
  44. progress_meter_image = Image("progress-meter_16bit.png");
  45. progress_fade_image = Image("progress-fade_16bit.png");
  46. fsck_progress_meter_image = Image("progress-meter_16bit.png");
  47. fsck_progress_fade_image = Image("fsck-fade_16bit.png");
  48.  
  49. }
  50. else {
  51.  
  52. logotype_image = Image("logo.png");
  53. progress_meter_image = Image("progress-meter.png");
  54. progress_fade_image = Image("progress-fade.png");
  55. fsck_progress_meter_image = Image("progress-meter.png");
  56. fsck_progress_fade_image = Image("fsck-fade.png");
  57.  
  58. }
  59.  
  60. /**/
  61.  
  62. /*
  63. * Sprites */
  64.  
  65. background_sprite = Sprite(background_image.Scale(screen_width, screen_height));
  66.  
  67. logotype_sprite = Sprite(logotype_image);
  68.  
  69. progress_meter_sprite = Sprite(progress_meter_image);
  70. progress_fade_sprite = Sprite(progress_fade_image);
  71.  
  72. fsck_progress_meter_sprite = Sprite(fsck_progress_meter_image);
  73. fsck_progress_fade_sprite = Sprite(fsck_progress_fade_image.Scale(1, fsck_progress_fade_image.GetHeight()));
  74.  
  75. passw_dialog_input_sprite = Sprite(passw_dialog_input_image);
  76. passw_lbl_sprite = Sprite();
  77.  
  78. msg_label_sprite = Sprite();
  79.  
  80. /**/
  81.  
  82. /*
  83. * Misc */
  84.  
  85. counter = 0;
  86.  
  87. fade_pos_x = (screen_width / 2) - (progress_meter_image.GetWidth() / 2);
  88. fade_dir = 0; /* 0 = right, 1 = left */
  89.  
  90. fsck_running = 0;
  91. fsck_dev_array;
  92. fsck_dev_counter = 0;
  93. fsck_fade_in_counter = 0;
  94. fsck_done_fading = 0;
  95.  
  96. stars_array;
  97. stars_n = 0;
  98.  
  99. //full_msg = "";
  100. msgs_line;
  101.  
  102. /**/
  103.  
  104. /*
  105. * Debug related */
  106.  
  107. debug = 0;
  108. debug_sprite = Sprite();
  109.  
  110. fun debugOutput(str) {
  111.  
  112. /*
  113. * This will print to the top left corner */
  114. debug_sprite.SetImage(Image.Text(str));
  115.  
  116. }
  117.  
  118. /**/
  119.  
  120. /*
  121. * Setup the graphics properties */
  122. logotype_sprite.SetPosition((screen_width / 2) - (logotype_image.GetWidth() / 2), (screen_height / 2) - (logotype_image.GetHeight() / 2));
  123.  
  124. progress_meter_sprite.SetPosition((screen_width / 2) - (progress_meter_image.GetWidth() / 2), (screen_height / 2) + (logotype_image.GetHeight() / 2));
  125.  
  126. fsck_progress_meter_sprite.SetPosition((screen_width / 2) - (progress_meter_image.GetWidth() / 2), (screen_height / 2) + (logotype_image.GetHeight() / 2) + 25);
  127. fsck_progress_fade_sprite.SetPosition((screen_width / 2) - (progress_meter_image.GetWidth() / 2), (screen_height / 2) + (logotype_image.GetHeight() / 2) + 25);
  128. fsck_progress_meter_sprite.SetOpacity(0);
  129. fsck_progress_fade_sprite.SetOpacity(0);
  130.  
  131. passw_dialog_input_sprite.SetPosition((screen_width / 2) - (passw_dialog_input_image.GetWidth() / 2), (screen_height / 2) + (logotype_image.GetHeight() / 2) + 50);
  132. passw_dialog_input_sprite.SetOpacity(0);
  133. passw_lbl_sprite.SetOpacity(0);
  134.  
  135. /*
  136. * this function only goes up to 100
  137. * because thats all thats needed for
  138. * the progress meter bar */
  139. fun atoi(str) {
  140.  
  141. int = -1;
  142.  
  143. for (i = 0; i <= 100; i++) {
  144.  
  145. if (i + "" == str) {
  146.  
  147. int = i;
  148.  
  149. break;
  150.  
  151. }
  152.  
  153. }
  154.  
  155. return int;
  156.  
  157. }
  158.  
  159. /*
  160. * This handler will/can be invoked
  161. * 50 times per second.
  162. *
  163. * According to the previous author of the
  164. * splash script, without this callback
  165. * the screen is not updated correctly */
  166. fun refreshHandler() {
  167.  
  168. progress_fade_sprite.SetPosition(fade_pos_x + counter, (screen_height / 2) + (logotype_image.GetHeight() / 2) - 2);
  169.  
  170. if (fade_dir == 0) {
  171.  
  172. counter++;
  173.  
  174. if (counter >= 200) {
  175.  
  176. fade_dir = 1;
  177.  
  178. }
  179.  
  180. }
  181. else {
  182.  
  183. counter--;
  184.  
  185. if (counter <= 0) {
  186.  
  187. fade_dir = 0;
  188.  
  189. }
  190.  
  191. }
  192.  
  193. if ((fsck_running == 1) && (fsck_done_fading == 0)) {
  194.  
  195.  
  196. fsck_progress_meter_sprite.SetOpacity(fsck_fade_in_counter);
  197. fsck_progress_fade_sprite.SetOpacity(fsck_fade_in_counter);
  198.  
  199. if (fsck_fade_in_counter < 1) {
  200.  
  201. fsck_fade_in_counter+= 0.025;
  202.  
  203. }
  204. else {
  205.  
  206. fsck_done_fading = 1;
  207.  
  208. }
  209.  
  210. }
  211.  
  212. }
  213.  
  214. Plymouth.SetRefreshFunction (refreshHandler);
  215.  
  216. /**/
  217.  
  218. /*
  219. * This function will display the password related information
  220. * when being prompt with entering a password */
  221. fun showPasswordHandler(prompt, stars) {
  222.  
  223. if (passw_dialog_input_sprite.GetOpacity() == 0 && passw_lbl_sprite.GetOpacity() == 0) {
  224.  
  225. passw_dialog_input_sprite.SetOpacity(1);
  226. passw_lbl_sprite.SetOpacity(1);
  227.  
  228. }
  229.  
  230. tmp_prompt_image = Image.Text(prompt, 1, 1, 1);
  231. /* tmp_prompt_image = tmp_prompt_image.Scale(tmp_prompt_image.GetWidth() - 15, tmp_prompt_image.GetHeight() - 5); */
  232. passw_lbl_sprite.SetImage(tmp_prompt_image);
  233. passw_lbl_sprite.SetPosition((screen_width / 2) - (tmp_prompt_image.GetWidth() / 2), (screen_height / 2) + (logotype_image.GetHeight() / 2) + 20);
  234.  
  235. for(i = 0; i < stars_n; i++) {
  236.  
  237. stars_array[i] = NULL;
  238.  
  239. }
  240.  
  241. stars_n = 0;
  242.  
  243. for(i = 0; (i < stars) && (i < 15); i++) {
  244.  
  245. stars_array[i] = Sprite(bullet_image);
  246. stars_array[i].SetPosition((((screen_width / 2) - (passw_dialog_input_image.GetWidth() / 2)) + (18 * i)) + 2, (screen_height / 2) + (logotype_image.GetHeight() / 2) + 55);
  247. stars_n++;
  248.  
  249. }
  250.  
  251. }
  252.  
  253. Plymouth.SetDisplayPasswordFunction(showPasswordHandler);
  254.  
  255. /**/
  256.  
  257. fun displayNormalHandler() {
  258.  
  259. /*
  260. * Hide the password dialog and the bullets */
  261.  
  262. if (passw_dialog_input_sprite.GetOpacity() == 1) {
  263.  
  264. passw_dialog_input_sprite.SetOpacity(0);
  265.  
  266. }
  267.  
  268. if (passw_lbl_sprite.GetOpacity() == 1) {
  269.  
  270. passw_lbl_sprite.SetOpacity(0);
  271.  
  272. }
  273.  
  274. for(i = 0; i < stars_n; i++) {
  275.  
  276. stars_array[i] = NULL;
  277.  
  278. }
  279.  
  280. }
  281.  
  282. Plymouth.SetDisplayNormalFunction(displayNormalHandler);
  283.  
  284. fun strlen(string) {
  285.  
  286. i = 0;
  287.  
  288. while (String(string).CharAt(i)) {
  289.  
  290. i++;
  291.  
  292. }
  293.  
  294. return i;
  295.  
  296. }
  297.  
  298. /*
  299. * This function will display the most current message */
  300. fun messageHandler(msg) {
  301.  
  302. if ((msg == "") || !msg) {
  303.  
  304. return 0;
  305.  
  306. }
  307.  
  308. if (msg.SubString(0, 5) == "keys:") {
  309.  
  310. msg = msg.SubString(5, strlen(msg)-5);
  311.  
  312. }
  313.  
  314. //full_msg += msg + " ";
  315. for(i = 4; i > 0; i--) {
  316.  
  317. msgs_line[i] = msgs_line[i - 1];
  318.  
  319. }
  320.  
  321. msgs_line[0] = Sprite(Image.Text(msg, 1, 1, 1));
  322. //tmp_image = Image.Text(full_msg, 1, 1, 1);
  323. /* tmp_image = tmp_image.Scale(tmp_image.GetWidth() - 15, tmp_image.GetHeight() - 5); */
  324.  
  325. dist = 1;
  326.  
  327. for(i = 0; i < 5; i++) {
  328.  
  329. //msg_label_sprite.SetImage(msgs_line[i]);
  330. //msg_label_sprite.SetPosition((screen_width / 2) - (msgs_line[i].GetWidth() / 2), screen_height - msgs_line[i].GetHeight() - (15*dist));
  331. msgs_line[i].SetPosition((screen_width / 2) - (msgs_line[i].GetImage().GetWidth() / 2), screen_height - msgs_line[i].GetImage().GetHeight() - (20*dist));
  332. dist++;
  333.  
  334. }
  335.  
  336. //msg_label_sprite.SetImage(tmp_image);
  337. //msg_label_sprite.SetPosition((screen_width / 2) - (tmp_image.GetWidth() / 2), screen_height - tmp_image.GetHeight() - 10);
  338.  
  339. }
  340.  
  341. Plymouth.SetMessageFunction(messageHandler);
  342.  
  343. /**/
  344.  
  345. /*
  346. * Handles the updates passed to the plymouth daemon
  347. * for example the FSCK data */
  348. fun statusHandler(status) {
  349.  
  350. tmp_char;
  351. status_array[0] = "";
  352. elem_count = 0;
  353.  
  354. for (i = 0; String(status).CharAt(i) != ""; i++) {
  355.  
  356. tmp_char = String(status).CharAt(i);
  357.  
  358. if (tmp_char != ":") {
  359.  
  360. status_array[elem_count] += tmp_char;
  361.  
  362. }
  363. else {
  364.  
  365. elem_count++;
  366. status_array[elem_count] = "";
  367.  
  368. }
  369.  
  370. }
  371.  
  372. if (status_array[0] == "fsck") {
  373.  
  374. already_added = 0;
  375.  
  376. if (fsck_running == 0) {
  377.  
  378. /*
  379. * use the dedicated message handler for this
  380. * since there is no messages about fsck checks
  381. * currently... */
  382. messageHandler("Routine disk drive check.");
  383.  
  384. fsck_running = 1;
  385.  
  386. }
  387.  
  388. for(i = 0; i < fsck_dev_counter; i++) {
  389.  
  390. /*
  391. * check if the device already exist and update
  392. * the progress only in that case */
  393. if (fsck_dev_array[i][0] == status_array[1]) {
  394.  
  395. fsck_dev_array[i][1] = status_array[2]; /* progress */
  396. already_added = 1;
  397.  
  398. }
  399.  
  400. }
  401.  
  402. /*
  403. * if the device is not added, then add it */
  404. if (already_added == 0) {
  405.  
  406. fsck_dev_array[fsck_dev_counter][0] = status_array[1]; /* device */
  407. fsck_dev_array[fsck_dev_counter][1] = status_array[2]; /* progress */
  408. fsck_dev_counter++;
  409.  
  410. }
  411.  
  412. /*
  413. * update the progress */
  414.  
  415. total = 0;
  416.  
  417. for(i = 0; i < fsck_dev_counter; i++) {
  418.  
  419. total += atoi(fsck_dev_array[i][1]);
  420.  
  421. }
  422.  
  423. if (fsck_dev_counter > 0) {
  424.  
  425. /*
  426. * display the total percentage */
  427. fsck_progress_fade_sprite.SetImage(fsck_progress_fade_image.Scale((fsck_progress_meter_image.GetWidth() / 100) * (total / fsck_dev_counter), fsck_progress_fade_image.GetHeight()));
  428.  
  429. }
  430.  
  431. /**/
  432.  
  433. /*
  434. * if the total progress is at maximum,
  435. * make the progress meter go away,
  436. * we might want to fade this out... */
  437. if (total == (100 * fsck_dev_counter)) {
  438.  
  439. fsck_progress_meter_sprite.SetOpacity(0);
  440. fsck_progress_fade_sprite.SetOpacity(0);
  441.  
  442. }
  443.  
  444. }
  445.  
  446. }
  447.  
  448. Plymouth.SetUpdateStatusFunction(statusHandler);
  449.  
  450. /**/
  451.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty