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. /*
  285. * This function will display the most current message */
  286. fun messageHandler(msg) {
  287.  
  288. if ((msg == "") || !msg) {
  289.  
  290. return 0;
  291.  
  292. }
  293. if (local.substring == "keys:") {
  294.  
  295. return 0;
  296.  
  297. }
  298.  
  299. //full_msg += msg + " ";
  300. for(i = 4; i > 0; i--) {
  301.  
  302. msgs_line[i] = msgs_line[i - 1];
  303.  
  304. }
  305.  
  306. msgs_line[0] = Sprite(Image.Text(msg, 1, 1, 1));
  307. //tmp_image = Image.Text(full_msg, 1, 1, 1);
  308. /* tmp_image = tmp_image.Scale(tmp_image.GetWidth() - 15, tmp_image.GetHeight() - 5); */
  309.  
  310. dist = 1;
  311.  
  312. for(i = 0; i < 5; i++) {
  313.  
  314. //msg_label_sprite.SetImage(msgs_line[i]);
  315. //msg_label_sprite.SetPosition((screen_width / 2) - (msgs_line[i].GetWidth() / 2), screen_height - msgs_line[i].GetHeight() - (15*dist));
  316. msgs_line[i].SetPosition((screen_width / 2) - (msgs_line[i].GetImage().GetWidth() / 2), screen_height - msgs_line[i].GetImage().GetHeight() - (20*dist));
  317. dist++;
  318.  
  319. }
  320.  
  321. //msg_label_sprite.SetImage(tmp_image);
  322. //msg_label_sprite.SetPosition((screen_width / 2) - (tmp_image.GetWidth() / 2), screen_height - tmp_image.GetHeight() - 10);
  323.  
  324. }
  325.  
  326. Plymouth.SetMessageFunction(messageHandler);
  327.  
  328. /**/
  329.  
  330. /*
  331. * Handles the updates passed to the plymouth daemon
  332. * for example the FSCK data */
  333. fun statusHandler(status) {
  334.  
  335. tmp_char;
  336. status_array[0] = "";
  337. elem_count = 0;
  338.  
  339. for (i = 0; String(status).CharAt(i) != ""; i++) {
  340.  
  341. tmp_char = String(status).CharAt(i);
  342.  
  343. if (tmp_char != ":") {
  344.  
  345. status_array[elem_count] += tmp_char;
  346.  
  347. }
  348. else {
  349.  
  350. elem_count++;
  351. status_array[elem_count] = "";
  352.  
  353. }
  354.  
  355. }
  356.  
  357. if (status_array[0] == "fsck") {
  358.  
  359. already_added = 0;
  360.  
  361. if (fsck_running == 0) {
  362.  
  363. /*
  364. * use the dedicated message handler for this
  365. * since there is no messages about fsck checks
  366. * currently... */
  367. messageHandler("Routine disk drive check.");
  368.  
  369. fsck_running = 1;
  370.  
  371. }
  372.  
  373. for(i = 0; i < fsck_dev_counter; i++) {
  374.  
  375. /*
  376. * check if the device already exist and update
  377. * the progress only in that case */
  378. if (fsck_dev_array[i][0] == status_array[1]) {
  379.  
  380. fsck_dev_array[i][1] = status_array[2]; /* progress */
  381. already_added = 1;
  382.  
  383. }
  384.  
  385. }
  386.  
  387. /*
  388. * if the device is not added, then add it */
  389. if (already_added == 0) {
  390.  
  391. fsck_dev_array[fsck_dev_counter][0] = status_array[1]; /* device */
  392. fsck_dev_array[fsck_dev_counter][1] = status_array[2]; /* progress */
  393. fsck_dev_counter++;
  394.  
  395. }
  396.  
  397. /*
  398. * update the progress */
  399.  
  400. total = 0;
  401.  
  402. for(i = 0; i < fsck_dev_counter; i++) {
  403.  
  404. total += atoi(fsck_dev_array[i][1]);
  405.  
  406. }
  407.  
  408. if (fsck_dev_counter > 0) {
  409.  
  410. /*
  411. * display the total percentage */
  412. 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()));
  413.  
  414. }
  415.  
  416. /**/
  417.  
  418. /*
  419. * if the total progress is at maximum,
  420. * make the progress meter go away,
  421. * we might want to fade this out... */
  422. if (total == (100 * fsck_dev_counter)) {
  423.  
  424. fsck_progress_meter_sprite.SetOpacity(0);
  425. fsck_progress_fade_sprite.SetOpacity(0);
  426.  
  427. }
  428.  
  429. }
  430.  
  431. }
  432.  
  433. Plymouth.SetUpdateStatusFunction(statusHandler);
  434.  
  435. /**/
  436.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty