home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / netscape6 / nim.xpi / bin / chrome / aim.jar / content / aim / AimTaskMenu.xul < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-27  |  9.5 KB  |  299 lines

  1. <?xml version="1.0"?>
  2.  
  3. <?xml-stylesheet href="chrome://aim/skin/aimTasksOverlay.css" type="text/css"?>
  4.  
  5. <!DOCTYPE overlay SYSTEM "chrome://aim/locale/AimTaskMenu.dtd" >
  6.  
  7. <overlay id="aimTaskMenuID"
  8.          xmlns:html="http://www.w3.org/1999/xhtml"
  9.          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  10.   
  11.   <script language="JavaScript" src="chrome://aim/content/aimHelpers.js" />
  12.   <script language="JavaScript" src="chrome://aim/content/AimSession.js" />
  13.   <script language="JavaScript" src="chrome://aim/content/App.js" /> 
  14.   <script language="JavaScript" src="chrome://aim/content/Aim.js" /> 
  15.  
  16.  
  17.   <keyset id="tasksKeys">
  18.     <key id="key_im"  key="&IMCmd.commandkey;" command="Tasks:IM" modifiers="accel"/>
  19.   </keyset>
  20.     
  21.  
  22.   <commandset id="tasksCommands">
  23.     <command id="Tasks:IM" oncommand="toOpenWindowByType('Aim:AimApp', 'chrome://aim/content/App.xul');"/>
  24.     <broadcaster id="IM:TaskIcon" online-state="offline"/> 
  25.   </commandset>
  26.   
  27.   
  28.   <menupopup id="taskPopup">
  29.     <menuitem id="IMMenuItem" position="2" label="&IMCmd.label;" accesskey="&IMCmd.accesskey;" key="key_im" command="Tasks:IM" />
  30.   </menupopup>
  31.   
  32.   <box id="component-bar">
  33.     <button class="button-toolbar-4 taskbutton" id="mini-aim" position="2" 
  34.             tooltip="aTooltip" tooltiptext="&IMCmd.tooltip;"
  35.             oncommand="toOpenWindowByType('Aim:AimApp', 'chrome://aim/content/App.xul');">
  36.       <observes element="IM:TaskIcon" attribute="online-state"/>
  37.     </button>
  38.   </box>
  39.  
  40. <script type="application/x-javascript">
  41.   <![CDATA[
  42.   var RDF = null;
  43.   function GetRDFService()
  44.   {
  45.     if ( RDF == null ) {
  46.       var RDFClass = Components.classes['@mozilla.org/rdf/rdf-service;1'];
  47.       RDF = RDFClass.getService(Components.interfaces.nsIRDFService);
  48.     }
  49.   }
  50.  
  51.   var AimIconObserver = new Object();
  52.  
  53.   AimIconObserver.onAssert = function(datasource, source, property, target) {
  54.     if (source.EqualsNode(aimRDFSession())) {
  55.       if (property.EqualsNode(aimRDFSessionState())) {
  56.       try {
  57.         var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  58.         var taskIconObserver = window.document.getElementById("IM:TaskIcon");  
  59.         if (state == "Offline") {
  60.           taskIconObserver.setAttribute("online-state", "offline");
  61.         }
  62.         else if (state == "Online") {
  63.           taskIconObserver.setAttribute("online-state", "online");
  64.         } 
  65.         else if (state == "OnlineAway") {
  66.            taskIconObserver.setAttribute("online-state", "away");
  67.         } 
  68.         else {
  69.            taskIconObserver.setAttribute("online-state", "offline");
  70.         }
  71.       }
  72.       catch (ex) 
  73.       {
  74.         //dump("\n cannot find aim task icon yet");
  75.       }
  76.      }
  77.    }
  78.  }
  79.  
  80.   AimIconObserver.onUnassert = function(datasource, source, property, target) {};
  81.   
  82.   AimIconObserver.onChange = function(datasource, source, property, oldTarget, newTarget) {
  83.     AimIconObserver.onAssert(datasource, source, property, newTarget);
  84.   };
  85.   
  86.   AimIconObserver.onMove = function(datasource, oldSource, newSource, property, target) {
  87.     AimIconObserver.onAssert(datasource, newSource, property, target);
  88.   };
  89.   
  90.   AimIconObserver.beginUpdateBatch = function(datasource) {
  91.   };
  92.  
  93.   AimIconObserver.endUpdateBatch = function(datasource) {
  94.   };
  95.  
  96.  /*
  97.   * Name: startobserve
  98.   *
  99.   * Arguments: none
  100.   *
  101.   * Description:
  102.   *
  103.   * This function is called on a timer until the AIM data source becomes available (this happens when the 
  104.   * user opens up AIM content in the sidebar). The purpose of this function is to register an observer on
  105.   * aim state changes. This observer (AIMIconObserver) is responsible for changing the running man icon 
  106.   * in the taskbar.
  107.   *
  108.   * Return Value: none
  109.   *
  110.   * Author: Syd Logan syd@netscape.com 5/18/2001
  111.   *
  112.  */
  113.  
  114.   function startobserve()
  115.   {
  116.     try {
  117.         if ( aimRDFDataSource() ) {
  118.             var im_state = aimRDFDataSource().GetTarget(aimRDFSession(), aimRDFSessionState(), true);
  119.             if (im_state == null)
  120.                 im_state = aimRDF().GetLiteral("Register");
  121.             AimIconObserver.onAssert(aimRDFDataSource(), aimRDFSession(), aimRDFSessionState(), im_state); 
  122.             aimRDFDataSource().AddObserver(AimIconObserver);  
  123.         } 
  124.         else {
  125.             setTimeout("startobserve()", 1000);
  126.         } 
  127.     }
  128.     catch ( ex ) {
  129.         setTimeout("startobserve()", 1000);
  130.     }
  131.   }
  132.  
  133.  /*
  134.   * Name: removeobserve
  135.   *
  136.   * Arguments: none
  137.   *
  138.   * Description:
  139.   *
  140.   * This function mimics startobserve, waiting until the observer has
  141.   * the AimIcon Observer has been set, then removes the Observer.
  142.   * Call this function when the xul file is removed.
  143.   *
  144.   * Return Value: none
  145.   *
  146.   * Author: Joseph Elwell jelwell@netscape.com 7/19/2001
  147.   *
  148.  */
  149.  
  150.   function removeobserve()
  151.   {
  152.         try {
  153.             if ( aimRDFDataSource() ) {
  154.                     aimRDFDataSource().RemoveObserver(AimIconObserver);  
  155.                 }
  156.                 else {
  157.                         setTimeout("removeobserve()", 1000);
  158.                 }
  159.         }
  160.         catch ( ex ) {
  161.                 setTimeout("removeobserve()", 1000);
  162.         }
  163.   }
  164.  
  165.  
  166. /*
  167.   * Name: checkAimAutoLogin()
  168.   * Arguments: none
  169.   * Description:
  170.   * This function is called everytime a component window( like nav, mail etc.) who can invoke an IM window
  171.   * from their New menu. The purpose of this function is to autologin to aim if that preference is set.
  172.   * There is a global pref appfirstlogin which is true if the user is launching the app and
  173.   * user has not signed to aim yet. If it is true, and all the necessary data for autologin is present,
  174.   * then the user is signed onto aim service. There is some  checks to see if aims idebar panel is clicked or 
  175.   * loaded on top in which case, this function just returns (since sidebar aim panel can take care of this scenario) 
  176.   * Return Value: none
  177. */
  178.  
  179. function checkAimAutoLogin()
  180. {
  181.   var first= aimPrefsManager().GetBoolPref("aim.session.appfirstlogin", null,true);
  182.   /* If user had already chosen to signoff in some sidebar after the app is launched */
  183.   if (first == false )
  184.       return;
  185.  
  186.   var panelset=document.getElementById("sidebar-panels");
  187.   for (var i=0; i<panelset.childNodes.length-1; i+=2) {
  188.     var panel=panelset.childNodes.item(i);
  189.     if (panel.getAttribute('id') == "urn:sidebar:panel:im-panel"){
  190.       if (panel.getAttribute('selected')) {
  191.         //already as top selected panel in sidebar - sidebar window load will do the rest-just return
  192.         return;
  193.       }
  194.     }
  195.   }
  196.  
  197.   var pIAimManager=Components.classes['@netscape.com/aim/IMManager;1'].getService(Components.interfaces.nsIIMManager);
  198.   var pIAimSession = pIAimManager.QueryInterface(Components.interfaces.nsIAimSession);
  199.   
  200.   //user already logged in - just return
  201.   var isOnline = pIAimSession.IsOnline();
  202.   if ( isOnline == true )
  203.     return;
  204.   
  205.   var autoLogin = aimPrefsManager().GetBoolPref("aim.session.autologin", null, false);
  206.   if (!autoLogin)
  207.    return;
  208.   
  209.   var screenName = aimPrefsManager().GetCharPref("aim.session.screenname", null, true);
  210.   if (!screenName || screenName == '')
  211.     return;
  212.    
  213.   if(pIAimSession)
  214.   {
  215.     var password = pIAimSession.GetSavedPassword(screenName);
  216.     if (!password || password == '')
  217.       return;
  218.     pIAimSession.Login(screenName, password, getsidebarframe());
  219.     aimMigrateBuddyList( aimSessionCurrentScreenName() );
  220.       return;
  221.     }
  222.   }
  223.  
  224. /*
  225.   * Name: loginObserver
  226.   * Arguments: none
  227.   * Description:
  228.   * If the user quits application then this observer listens to it and 
  229.   * resets appfirstlogin   preference back to true.
  230.   * Return Value: none
  231. */
  232.                      
  233. var loginObserver = {
  234.   Observe: function(subject, message, data) {
  235.     if (message == 'quit-application') 
  236.       aimPrefsManager().SetBoolPref("aim.session.appfirstlogin",true,null, true);
  237.   }
  238. }
  239.  
  240.  
  241. /*
  242.   * Name: addLoadListener()
  243.   * Arguments: none
  244.   * Description:
  245.   * This function is called on the load of the window. This will add an observer
  246.   * which will wait for the "quit" application message.
  247.   * Return Value: none
  248. */
  249.  
  250. function addLoadListener() {
  251.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  252.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  253.   if (observerService) {
  254.     observerService.AddObserver(loginObserver, "quit-application");
  255.   } else {
  256.     //dump("failed to get observer service\n");
  257.   }
  258.  
  259.   // On load of this window, if there is a sidebar, check for aim auto login
  260.   if (document.getElementById('sidebar-box'))
  261.     checkAimAutoLogin();
  262. }
  263.  
  264.  
  265. /*
  266.   * Name: removeLoadListener()
  267.   * Arguments: none
  268.   * Description:
  269.   * This function is called on the unload of the window. This will remove the loginObserver
  270.   * Return Value: none
  271. */
  272.  
  273.  
  274. function removeLoadListener() {
  275.   var observerService = Components.classes["@mozilla.org/observer-service;1"].getService();
  276.   observerService = observerService.QueryInterface(Components.interfaces.nsIObserverService);
  277.   if (observerService)
  278.     {
  279.       observerService.RemoveObserver(loginObserver, "quit-application");
  280.     }
  281. }
  282.  
  283.  
  284.   // start the ball rolling
  285.  
  286.   setTimeout("startobserve()", 1000);
  287.   addEventListener("unload",removeobserve,true);
  288.  
  289.     // Add listeners for sidebar autologin
  290.   /*window.addEventListener("load", addLoadListener, false); 
  291.   window.addEventListener("unload", removeLoadListener, false);  
  292.   Commenting out until presense crash has been figured out
  293. */
  294.  
  295. ]]>
  296. </script>         
  297.  
  298. </overlay>
  299.