/* * This code is Copyright (c) 2006 Derek den Haas and Sjoerd van der Hoorn, * all rights reserved. This code is for use with the vOS virtual GUI. Do * not use these files within your own projects. Redistribution and use in * source and binary forms, with or without modification, are not permitted. * More information about vOS can be found at http://www.vschool.nl/. */ // Class prototype // --------------- function vApp(_vApp_file, _vApp_parameters) { //The functions this.load = _vApp_load; this.data = _vApp_data; this.enable = _vApp_enable; this.disable = _vApp_disable; this.stop = _vApp_stop; this.vAlert = _vApp_vAlert; this.vPrompt = _vApp_vPrompt; //The variables this.vApp_pid = vOS.arr_vApps.length; this.vApp_file = _vApp_file; this.vApp_parameters = _vApp_parameters; this.vApp_process = "vOS.arr_vApps[" + this.vApp_pid + "]"; this.vApp_path = this.vApp_file.indexOf("/") > 0 ? _vApp_file.substr(0, _vApp_file.lastIndexOf("/") + 1) : ""; this.timers = new Array(); vOS.arr_vApps[this.vApp_pid] = this; //Begin script if (typeof(vOS.arr_vPrograms[this.vApp_file]) != "object") { //cache queue vOS.arr_vPrograms[this.vApp_file] = new Array(); vOS.arr_vPrograms[this.vApp_file]['state'] = 2; var _vApp_xml_request = new Array(); _vApp_xml_request["xml"] = new XMLHttpRequest(); // Keep the vApp id in cache! _vApp_xml_request["id"] = this.vApp_pid; if (_vApp_xml_request["xml"]) { _vApp_xml_request["xml"].onreadystatechange = function() { if (_vApp_xml_request["xml"].readyState == 4 && _vApp_xml_request["xml"].status == 200) { var that = vOS.arr_vApps[_vApp_xml_request["id"]]; vOS.vTime_change(_vApp_xml_request["xml"].getResponseHeader("Date")); // put in cache vOS.arr_vPrograms[that.vApp_file]['code'] = _vApp_xml_request["xml"].responseText; vOS.arr_vPrograms[that.vApp_file]['state'] = 1; // Load it that.load(_vApp_xml_request["xml"].responseText); // ! No cache vOS.arr_vPrograms[that.vApp_file] = undefined; return; } if (_vApp_xml_request["xml"].readyState == 4 && _vApp_xml_request["xml"].status != 200) { var that = vOS.arr_vApps[_vApp_xml_request["id"]]; alert("Program \"" + that.vApp_file + "\" doesn't exists!\nStatus: "+_vApp_xml_request["xml"].status); that.stop(); //Program doesn't exists or server down, don't cache! vOS.arr_vPrograms[that.vApp_file] = undefined; return; } } _vApp_xml_request["xml"].open("POST", _vApp_file, true); _vApp_xml_request["xml"].setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); _vApp_xml_request["xml"].send(""); } } else if (vOS.arr_vPrograms[this.vApp_file]['state'] == 1) { // Load the code this.load(vOS.arr_vPrograms[this.vApp_file]['code']); } else if (vOS.arr_vPrograms[this.vApp_file]['state'] == 2) { //Flood of this program, don't load it :) alert("Still loading an application, can't open it again!"); this.stop(); } //Now the functions: function _vApp_load(_vApp_code) { //It's now back in the right THIS :D eval(_vApp_code); this.onLoad(this.vApp_parameters); } function _vApp_data(_vApp_callback, _vApp_file, _vApp_parameters_array, _vApp_callbackparameters) { // Call the function to load data from external files vOS.data("vApp", _vApp_callback, _vApp_file, _vApp_parameters_array, _vApp_callbackparameters, this.vApp_pid) } function _vApp_enable() { // Enable all disabled windows within the application var x = 0; while (x < vOS.arr_vWindows.length) { if (vOS.arr_vWindows[x].vApp_pid == this.vApp_pid) { vOS.arr_vWindows[vOS.arr_vWindows[x].vWindow_id].enable(); } x++; } return null; } function _vApp_disable() { // Disable all the windows within the application. Keep in mind that you can make new windows who's status won't be disabled var x = 0; while (x < vOS.arr_vWindows.length) { if (vOS.arr_vWindows[x].vApp_pid == this.vApp_pid) { vOS.arr_vWindows[vOS.arr_vWindows[x].vWindow_id].disable(); } x++; } return null; } function _vApp_stop() { // Shut down the application completely by removing all windows, taskbar icons // and scripts related to it. // Stop timers for(var x = 0; x < this.timers.length; x++) { this.timers[x].stop(); } var x = 0; // Close windows while (x < vOS.arr_vWindows.length) { if (vOS.arr_vWindows[x].vApp_pid == this.vApp_pid) { vOS.arr_vWindows[vOS.arr_vWindows[x].vWindow_id].close(); x = -1; } x++; } // Remove taskbar icons var x = 0 while (x < vOS.taskbar.taskbar_icons.childNodes.length) { if (vOS.taskbar.taskbar_icons.childNodes[x].vApp_pid == this.vApp_pid) { vOS.taskbar.taskbar_icons.removeChild(vOS.taskbar.taskbar_icons.childNodes[x]); x = -1; } x++; } // And remove all code corresponding with this application vOS.arr_vApps[this.vApp_pid] = undefined; // Return nothing return 1; } function _vApp_vAlert(_vApp_vAlert_text, _vApp_vAlert_title, _vApp_vAlert_buttons) { // Call the function in vOS.vDialog to show a vAlert vOS.vDialog.vAlert(_vApp_vAlert_text, _vApp_vAlert_title, _vApp_vAlert_buttons, "vApp", this); } function _vApp_vPrompt(_vApp_vPrompt_text, _vApp_vPrompt_title, _vApp_vPrompt_default) { // Call the function in vOS.vDialog to show a vPrompt vOS.vDialog.vPrompt(_vApp_vPrompt_text, _vApp_vPrompt_title, _vApp_vPrompt_default, "vApp", this); } } add_counter(10);