home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 May / 05_02.iso / software / netscape6 / nim.xpi / bin / chrome / aim.jar / content / aim / Aim.js < prev    next >
Encoding:
Text File  |  2001-05-22  |  6.5 KB  |  306 lines

  1. var strBundleService = null;
  2. var regionalBundle = null;
  3.  
  4. /* 
  5.  * Name: aimRDF
  6.  *
  7.  * Arguments: None
  8.  *
  9.  * Description:
  10.  *
  11.  * Returns: the nsIRDF service
  12.  *
  13.  * Author: syd@netscape.com 5/18/2001
  14.  *
  15. */
  16.  
  17. function aimRDF()
  18. {
  19.     var RDF = null;
  20.  
  21.     try {
  22.         var RDFClass = Components.classes["@mozilla.org/rdf/rdf-service;1"];
  23.         if ( RDFClass )
  24.             RDF = RDFClass.getService(Components.interfaces.nsIRDFService);
  25.     }
  26.     catch( ex ) {
  27.     }
  28.  
  29.     return RDF;
  30.  
  31. }
  32.  
  33. /* 
  34.  * Name: aimRDFDataSource
  35.  *
  36.  * Arguments: None
  37.  *
  38.  * Description:
  39.  *
  40.  * Returns: the AIM rdf data source
  41.  *
  42.  * Author: syd@netscape.com 5/18/2001
  43.  *
  44. */
  45.  
  46. function aimRDFDataSource()
  47. {
  48.     var AimDataSource = null;
  49.     try {
  50.         var rdf = aimRDF();
  51.         if ( rdf ) {
  52.             AimDataSource = rdf.GetDataSource("rdf:AIM");
  53.         }
  54.     } catch (ex) {}
  55.  
  56.     return AimDataSource;
  57. }
  58.  
  59. /* 
  60.  * Name: aimRDFSession
  61.  *
  62.  * Arguments: None
  63.  *
  64.  * Description:
  65.  *
  66.  * Returns: the NC:AIM/session resource
  67.  *
  68.  * Author: syd@netscape.com 5/18/2001
  69.  *
  70. */
  71.  
  72. function aimRDFSession()
  73. {
  74.     var rdf = aimRDF();
  75.     if ( rdf ) {
  76.         return rdf.GetResource("NC:AIM/Session");
  77.     }
  78.     return null;
  79. }
  80.  
  81. /* 
  82.  * Name: aimRDFSessionState
  83.  *
  84.  * Arguments: None
  85.  *
  86.  * Description:
  87.  *
  88.  * Returns: the OnlineState resource
  89.  *
  90.  * Author: syd@netscape.com 5/18/2001
  91.  *
  92. */
  93.  
  94. function aimRDFSessionState()
  95. {
  96.     var rdf = aimRDF();
  97.     if ( rdf ) {
  98.         return rdf.GetResource("http://home.netscape.com/NC-rdf#OnlineState");
  99.     }
  100.     return null;
  101. }
  102.  
  103. /* 
  104.  * Name: aimRDFWarningStatus
  105.  *
  106.  * Arguments: None
  107.  *
  108.  * Description:
  109.  *
  110.  * Returns: the nsIRDF service
  111.  *
  112.  * Author: syd@netscape.com 5/18/2001
  113.  *
  114. */
  115.  
  116. function aimRDFWarningStatus()
  117. {
  118.     var rdf = aimRDF();
  119.     if ( rdf ) {
  120.         return rdf.GetResource("http://home.netscape.com/NC-rdf#Warning");
  121.     }
  122.     return null;
  123. }
  124.  
  125. function aimGetStrBundle(path)
  126. {
  127.   var strBundle = null;
  128.  
  129.   if (!strBundleService) {
  130.       try {
  131.           strBundleService =
  132.               Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
  133.           strBundleService = 
  134.               strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
  135.       } catch (ex) {
  136.           dump("\n--** aimGetStrBundle: strBundleService failed: " + ex + "\n");
  137.           return null;
  138.       }
  139.   }
  140.  
  141.   strBundle = strBundleService.createBundle(path); 
  142.   if (!strBundle) {
  143.     dump("\n--** aimGetStrBundle: strBundle createInstance " + path + " failed **--\n");
  144.   }
  145.   return strBundle;
  146. }
  147.  
  148. function aimRegionString(name)
  149. {
  150.     if (!regionalBundle) {
  151.         regionalBundle = aimGetStrBundle("chrome://aim-region/locale/region.properties");
  152.     }
  153.  
  154.     if (regionalBundle) {
  155.         try {
  156.             return regionalBundle.GetStringFromName(name);
  157.         } catch (ex) {
  158.             dump("\n-->aimRegionString(name)=" + name + " failed! \n");    
  159.         }
  160.     }
  161.     return "";
  162. }
  163.  
  164. function aimGetArgs(data)
  165. {
  166.     var args = new Object();
  167.     var pairs = data.split(",");
  168.     dump("GetArgs: argument: {" + data + "}\n");
  169.  
  170.     for (var i = pairs.length - 1; i >= 0; i--)
  171.     {
  172.         var pos = pairs[i].indexOf('=');
  173.         if (pos == -1)
  174.             continue;
  175.         var argname = pairs[i].substring(0, pos);
  176.         var argvalue = pairs[i].substring(pos + 1);
  177.         if (argvalue.charAt(0) == "'" && argvalue.charAt(argvalue.length - 1) == "'")
  178.             args[argname] = argvalue.substring(1, argvalue.length - 1);
  179.         else
  180.             args[argname] = unescape(argvalue);
  181.     }
  182.     return args;
  183. }
  184.  
  185. function aimString(name)
  186. {
  187.  
  188.     var myAimSession = aimSession();
  189.     if ( myAimSession ) {
  190.         var pIStringBundle = aimSession().QueryInterface(Components.interfaces.nsIStringBundle);
  191.         if (pIStringBundle)
  192.             return pIStringBundle.GetStringFromName(name);
  193.     }
  194.     return "";
  195. }
  196.  
  197. function aimErrorBox(errorText)
  198. {
  199.     top.alert(errorText);
  200. }
  201.  
  202. /* Global menu commands. Menu commands that might be useful to multiple apps go here */
  203.  
  204. function aimCmdNewBrowser(url)
  205. {
  206.     var Browser_pref=null;
  207.     try
  208.     {
  209.           Browser_pref = Components.classes["@mozilla.org/preferences;1"];
  210.           if (Browser_pref)       Browser_pref = Browser_pref.getService();
  211.           if (Browser_pref)       Browser_pref = Browser_pref.QueryInterface(Components.interfaces.nsIPref);
  212.     }
  213.     catch (ex)
  214.     {
  215.           dump("failed to get prefs service!\n");
  216.           Browser_pref = null;
  217.     }
  218.  
  219.     if (Browser_pref.GetBoolPref("network.protocols.useSystemDefaults"))
  220.      {
  221.         var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI); 
  222.         uri.spec=url;
  223.         aimAdminManager().LoadDefaultBrowser(uri);
  224.         }
  225.     else
  226.         window.openDialog( "chrome://navigator/content/navigator.xul", "_blank", "chrome,all,dialog=no", url);
  227. }
  228.  
  229.  
  230. function aimCmdNewEmail()
  231. {
  232.     dump("Implement Menu Command cmdNewEmail()\n");
  233.  
  234.     openDialog("chrome://messenger/content/messengercompose/messengercompose.xul", "");
  235.     dump( "Leaving aimCmdNewEmail()\n" );
  236.  
  237. }
  238.  
  239. // this function tries to find where the groups data in the tree starts, 
  240. // and returns the node, else null. 
  241.  
  242. function aimBuddyTreeFindGroups( tree )
  243. {
  244.     if ( !tree ) {
  245.         return( null);
  246.     }
  247.  
  248.     else if ( !tree.childNodes )
  249.     {
  250.         return( null );
  251.     }
  252.  
  253.     for ( var i = 0; i < tree.childNodes.length; i++ ) {
  254.         if ( tree.childNodes[i].nodeName == "treechildren" ) {
  255.             return( tree.childNodes[i].childNodes );
  256.         }
  257.     }
  258.     return( null );
  259. }
  260.  
  261. function aimGlobalCmdStartupWizard()
  262. {
  263.     var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  264.  
  265.     var    windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
  266.  
  267.     var topWindow = windowManagerInterface.getMostRecentWindow("Aim:StartupWizard");
  268.   if(topWindow)
  269.     topWindow.focus();
  270.   else
  271.     window.openDialog('chrome://aim/content/migrationWizard.xul','CPW','chrome,titlebar,resizable=yes',document);
  272. }
  273.  
  274. function ClearMenuList( menulist )
  275. {
  276.     if ( menulist ) {
  277.         menulist.selectedItem = null;
  278.         while( menulist.firstChild )
  279.             menulist.removeChild( menulist.firstChild );
  280.     }
  281. }
  282.  
  283. function AppendStringToMenulist(menulist, string)
  284. {
  285.   if (menulist) {
  286.     var menupopup = menulist.firstChild;
  287.     // May not have any popup yet -- so create one
  288.     if (!menupopup) {
  289.       menupopup = document.createElement("menupopup");
  290.       if (menupopup)
  291.         menulist.appendChild(menupopup);
  292.       else {
  293.         dump("Failed to create menupoup\n");
  294.         return null;
  295.       }
  296.     }
  297.     menuItem = document.createElement("menuitem");
  298.     if (menuItem) {
  299.       menuItem.setAttribute("label", string);
  300.       menupopup.appendChild(menuItem);
  301.       return menuItem;
  302.     }
  303.   }
  304.   return null;
  305. }
  306.