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