home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Freeware / Programare / paranoia / ParanoiaSetup.exe / Gui / Home.js < prev    next >
Text File  |  2005-03-23  |  7KB  |  250 lines

  1. /* Global Varibles */
  2. var g_G1Connected = false;
  3. var g_G2Connected = false;
  4.  
  5. function OnloadHome(){
  6.     CommonOnload();
  7. }
  8.  
  9.  
  10. /*
  11.  * function: GetNetworkStatusFunction
  12.  * Description: The following function called by the program. 
  13.  * Use it to retrieves information about the network status and update the GUI.
  14.  */
  15. function GetNetworkStatusFunction()
  16. {
  17.     /*
  18.      * Calling the IsConnected function for connection status of both G1 and G2:
  19.      * 0 - Connecting
  20.      * 1 - Connected
  21.      * 2 - Disconnected
  22.      * Set the result in an Object with the ID = IsConnectedID
  23.      */
  24.     ExecuteCommand("IsConnected|SEPERATOR|IsConnectedID");
  25.     
  26.     /* Get the connection status for G1 and G2 */
  27.     ExecuteCommand("IsConnectedG1|SEPERATOR|IsConnectedG1ID");
  28.     ExecuteCommand("IsConnectedG2|SEPERATOR|IsConnectedG2ID");
  29.     
  30.     /* Get the "Known Nodes" information */
  31.     ExecuteCommand("GetKnownNodes|SEPERATOR|<NodeIP><br>|SEPERATOR|KnownNodesID");
  32.     /* Get cache nodes information */
  33.     ExecuteCommand("GetCacheInfo|SEPERATOR|CachedPercentID");
  34.  
  35.     /* Get connected nodes information */
  36.     //ExecuteCommand("GetConnectedNodes|SEPERATOR|<NodeIP><br>|SEPERATOR|ConnectedNodesID");    
  37.  
  38.  
  39.     ExecuteCommand("GetConnectedG1Nodes|SEPERATOR|<span onmouseover=GetNodeInfo(<NodeID>) style='color:#838383'><NodeIP> (Gnutella1)</span> - <span class='SmallCommandLink' onclick=RemoveNode(<NodeID>)>Remove</span><br>|SEPERATOR|ConnectedG1NodesID");    
  40.     ExecuteCommand("GetConnectedG2Nodes|SEPERATOR|<span onmouseover=GetNodeInfo(<NodeID>) style='color:#46CCEF'><NodeIP> (Gnutella2)</span> - <span class='SmallCommandLink' onclick=RemoveNode(<NodeID>)>Remove</span><br>|SEPERATOR|ConnectedG2NodesID");    
  41.     
  42.     SetNetworkStatusText();
  43. }
  44.  
  45. /*
  46.  * function: SetNetworkStatusText
  47.  * Description: The following function is responsible for handling any interface 
  48.  * update
  49.  */
  50. function SetNetworkStatusText()
  51. {
  52.     /* According to the result of GetNetworkStatus set the status text on the interface */
  53.     SetConnectionStatusText();
  54.     
  55.     /* Take the hidden connected nodes text for G1 + G2 and present them together */
  56.     SetConnectedG1G2NodesText()
  57.     
  58.     /* Set the text of the connection buttons (G1/G2)*/
  59.     SetG1ConnectionButtonStyle();
  60.     SetG2ConnectionButtonStyle();
  61.     
  62. }
  63.  
  64. function SetConnectedG1G2NodesText()
  65. {
  66.     var lsConnectedNodesStatus = ConnectedG1NodesID.innerHTML + ConnectedG2NodesID.innerHTML;
  67.     ConnectedNodesID.innerHTML = lsConnectedNodesStatus;
  68.     
  69. }
  70. /*
  71.  * function: SetConnectionStatusText
  72.  * Description: Set the text for the connection status:  Connecting/Connected/Disconnected
  73.  */
  74. function SetConnectionStatusText()
  75. {
  76.     
  77.     if(document.all.IsConnectedID.innerHTML == "0")
  78.     {
  79.         document.all.StatusTextID.innerHTML = "Status: Connecting...";
  80.         return;
  81.     }
  82.     
  83.     if(document.all.IsConnectedID.innerHTML == "1")
  84.     {
  85.         document.all.StatusTextID.innerHTML = "Status: Connected";
  86.         return;
  87.     }
  88.     
  89.     if(document.all.IsConnectedID.innerHTML == "2")
  90.     {
  91.         document.all.StatusTextID.innerHTML = "Status: Disconnected";
  92.         return;
  93.     }
  94.     
  95.     // In case none of the above set the status to unknown    
  96.     document.all.StatusTextID.innerHTML = "Status: Unknown";
  97.     return;
  98.     
  99. }
  100.  
  101. /*
  102.  * function: SetG1ConnectionButtonText
  103.  * Description: Set the text for the G1 connection Button and sets the status of
  104.  * the G1 global variable: g_G1Connected
  105.  */
  106. function SetG1ConnectionButtonStyle()
  107. {
  108.     if(document.all.IsConnectedG1ID.innerHTML == "2")
  109.     {
  110.         ConnectButtonG1ID.style.border = '0px';
  111.         ConnectButtonG1ID.style.backgroundColor = "#E6E6E6";
  112.         g_G1Connected = false;
  113.         
  114.     }else
  115.     {
  116.         
  117.         ConnectButtonG1ID.style.border = '1px solid black';
  118.         ConnectButtonG1ID.style.backgroundColor = "#D2DEF2";
  119.         g_G1Connected = true;
  120.     }
  121.     
  122.     
  123. }
  124.  
  125. /*
  126.  * function: SetG2ConnectionButtonText
  127.  * Description: Set the text for the G2 connection Button and sets the status of
  128.  * the G1 global variable: g_G2Connected
  129.  */
  130. function SetG2ConnectionButtonStyle()
  131. {
  132.  
  133.     if(document.all.IsConnectedG2ID.innerHTML == "2")
  134.     {
  135.         ConnectButtonG2ID.style.border = '0px';
  136.         ConnectButtonG2ID.style.backgroundColor = "#E6E6E6";
  137.         g_G2Connected = false;
  138.         
  139.     }else
  140.     {
  141.         
  142.         ConnectButtonG2ID.style.border = '1px solid black';
  143.         ConnectButtonG2ID.style.backgroundColor = "#D2DEF2";
  144.         g_G2Connected = true;
  145.     }
  146.     
  147.     
  148. }
  149.  
  150. /*
  151.  * function: ToggleConnection
  152.  * Parameters:
  153.  * Network - The network ID: 0 = G1, 1= G2
  154.  * Description: Toggle connection status of the network according to the global variable g_G2Connected
  155.  */
  156.  
  157. function ToggleConnection(Network)
  158. {
  159.  
  160.     if(Network == 0) //G1
  161.     {
  162.         if(g_G1Connected)
  163.         {
  164.             ExecuteCommand("DisconnectG1");
  165.             ConnectButtonG1ID.style.border = '0px';
  166.             ConnectButtonG1ID.style.backgroundColor = "#E6E6E6";
  167.             
  168.         }
  169.         else
  170.         {
  171.  
  172.             ExecuteCommand("ConnectG1");
  173.             ConnectButtonG1ID.style.border = '1px solid black';
  174.             ConnectButtonG1ID.style.backgroundColor = "#D2DEF2";
  175.         }
  176.     }
  177.     
  178.     if(Network == 1) //G2
  179.     {
  180.         if(g_G2Connected)
  181.         {
  182.             ExecuteCommand("DisconnectG2");
  183.             ConnectButtonG2ID.style.border = '0px';
  184.             ConnectButtonG2ID.style.backgroundColor = "#E6E6E6";
  185.         }
  186.         else
  187.         {
  188.             ExecuteCommand("ConnectG2");
  189.             ConnectButtonG2ID.style.border = '1px solid black';
  190.             ConnectButtonG2ID.style.backgroundColor = "#D2DEF2";
  191.         }
  192.     }
  193. }
  194. /*
  195.  * function: RefreshCache
  196.  * Description: This function call the webcache to get more nodes
  197.  */
  198. function RefreshCache()
  199. {
  200.     ExecuteCommand("RefreshCache");
  201. }
  202.  
  203. /*
  204.  * function: ShowNodeInfo
  205.  * Parameters:
  206.  * NodeID: The ID of the node - a reference number to it.
  207.  * Description: This function shows more information on a specific connected node.
  208.  */
  209. function GetNodeInfo(NodeID)
  210. {
  211.     var lsCommand;
  212.     lsCommand = "GetNodeInfo|SEPERATOR|" + NodeID + "|SEPERATOR|";
  213.     lsCommand += "IP: <IP><BR>\
  214.                   Time Connected: <TimeConnected><BR>\
  215.                   Bandwidth: <BandWidth> KB/s<BR>\
  216.                   Efficiency: <Efficiency><BR>\
  217.                   Agent: <Agent><BR>\
  218.                   Mode: <Mode><BR>";
  219.  
  220.     lsCommand += "|SEPERATOR|NodeInfoID";
  221.     
  222.     ExecuteCommand(lsCommand);
  223. }
  224.  
  225. /*
  226.  * function: RemoveNode
  227.  * Parameters:
  228.  * NodeID: The ID of the node - a reference number to it.
  229.  * Description: This function disconnects a node.
  230.  */
  231. function RemoveNode(NodeID)
  232. {
  233.     var lsCommand;
  234.     lsCommand = "RemoveNode|SEPERATOR|" + NodeID;
  235.     ExecuteCommand(lsCommand);
  236. }
  237.  
  238. /*
  239.  * function: ConnectNode
  240.  * Parameters:
  241.  * IP: IP string in the format of xxx.xxx.xxx.xxx
  242.  * Port: The port of the node
  243.  * Description: This function Connects to a node.
  244.  */
  245. function ConnectNode(IP,Port)
  246. {
  247.     var lsCommand;
  248.     lsCommand = "ConnectNode|SEPERATOR|" + IP + "|SEPERATOR|" + Port;
  249.     ExecuteCommand(lsCommand);
  250. }