home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 June / PCpro_2006_06.ISO / files / firefox / calendar_windows_latest.xpi / components / calItemModule.js < prev    next >
Encoding:
Text File  |  2006-01-16  |  9.8 KB  |  256 lines

  1. /* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is Oracle Corporation code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  *  Oracle Corporation
  19.  * Portions created by the Initial Developer are Copyright (C) 2004
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Vladimir Vukicevic <vladimir.vukicevic@oracle.com>
  24.  *   Mike Shaver <shaver@off.net>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  28.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. const kCalRecurrenceInfoContractID = "@mozilla.org/calendar/recurrence-info;1";
  41. const kCalIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
  42.  
  43. const kCalRecurrenceRuleContractID = "@mozilla.org/calendar/recurrence-rule;1";
  44. const kCalIRecurrenceRule = Components.interfaces.calIRecurrenceRule;
  45.  
  46. const kCalRecurrenceDateSetContractID = "@mozilla.org/calendar/recurrence-date-set;1";
  47. const kCalIRecurrenceDateSet = Components.interfaces.calIRecurrenceDateSet;
  48.  
  49. const kCalRecurrenceDateContractID = "@mozilla.org/calendar/recurrence-date;1";
  50. const kCalIRecurrenceDate = Components.interfaces.calIRecurrenceDate;
  51.  
  52. /* Constructor helpers, lazily initialized to avoid registration races. */
  53. var CalRecurrenceInfo = null;
  54. var CalRecurrenceRule = null;
  55. var CalRecurrenceDateSet = null;
  56. var CalRecurrenceDate = null;
  57. var CalDateTime = null;
  58. var CalDuration = null;
  59. var CalAttendee = null;
  60.  
  61. var componentInitRun = false;
  62. function initBaseComponent()
  63. {
  64.     CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
  65.     CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
  66.     CalRecurrenceDateSet = new Components.Constructor(kCalRecurrenceDateSetContractID, kCalIRecurrenceDateSet);
  67.     CalRecurrenceDate = new Components.Constructor(kCalRecurrenceDateContractID, kCalIRecurrenceDate);
  68.  
  69.     CalDateTime = new Components.Constructor("@mozilla.org/calendar/datetime;1",
  70.                                              Components.interfaces.calIDateTime);
  71.     CalDuration = new Components.Constructor("@mozilla.org/calendar/duration;1",
  72.                                              Components.interfaces.calIDateTime);
  73.     CalAttendee = new Components.Constructor("@mozilla.org/calendar/attendee;1",
  74.                                              Components.interfaces.calIAttendee);
  75. }
  76.  
  77.  
  78. /* Update these in calBaseCID.h */
  79. const componentData =
  80.     [
  81.      /* calItemBase must be first: later scripts depend on it */
  82.     {cid: null,
  83.      contractid: null,
  84.      script: "calItemBase.js",
  85.      constructor: null},
  86.  
  87.     {cid: Components.ID("{f42585e7-e736-4600-985d-9624c1c51992}"),
  88.      contractid: "@mozilla.org/calendar/manager;1",
  89.      script: "calCalendarManager.js",
  90.      constructor: "calCalendarManager",
  91.      onComponentLoad: "onCalCalendarManagerLoad()"},
  92.  
  93.     {cid: Components.ID("{7a9200dd-6a64-4fff-a798-c5802186e2cc}"),
  94.      contractid: "@mozilla.org/calendar/alarm-service;1",
  95.      script: "calAlarmService.js",
  96.      constructor: "calAlarmService",
  97.      category: "app-startup",
  98.      categoryEntry: "alarm-service-startup",
  99.      service: true},
  100.  
  101.     {cid: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
  102.      contractid: "@mozilla.org/calendar/event;1",
  103.      script: "calEvent.js",
  104.      constructor: "calEvent"},
  105.  
  106.     {cid: Components.ID("{7af51168-6abe-4a31-984d-6f8a3989212d}"),
  107.      contractid: "@mozilla.org/calendar/todo;1",
  108.      script: "calTodo.js",
  109.      constructor: "calTodo"},
  110.  
  111.     {cid: Components.ID("{5c8dcaa3-170c-4a73-8142-d531156f664d}"),
  112.      contractid: "@mozilla.org/calendar/attendee;1",
  113.      script: "calAttendee.js",
  114.      constructor: "calAttendee"},
  115.  
  116.     {cid: Components.ID("{5f76b352-ab75-4c2b-82c9-9206dbbf8571}"),
  117.      contractid: "@mozilla.org/calendar/attachment;1",
  118.      script: "calAttachment.js",
  119.      constructor: "calAttachment"},
  120.  
  121.     {cid: Components.ID("{04027036-5884-4a30-b4af-f2cad79f6edf}"),
  122.      contractid: "@mozilla.org/calendar/recurrence-info;1",
  123.      script: "calRecurrenceInfo.js",
  124.      constructor: "calRecurrenceInfo"},
  125.  
  126.     {cid: Components.ID("{4123da9a-f047-42da-a7d0-cc4175b9f36a}"),
  127.      contractid: "@mozilla.org/calendar/datetime-formatter;1",
  128.      script: "calDateTimeFormatter.js",
  129.      constructor: "calDateTimeFormatter"}
  130.     ];
  131.  
  132. var calItemModule = {
  133.     mScriptsLoaded: false,
  134.     loadScripts: function () {
  135.         if (this.mScriptsLoaded)
  136.             return;
  137.  
  138.         const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
  139.         const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
  140.  
  141.         const dirsvcContractID = "@mozilla.org/file/directory_service;1";
  142.         const propsIID = Components.interfaces.nsIProperties;
  143.  
  144.         const iosvcContractID = "@mozilla.org/network/io-service;1";
  145.         const iosvcIID = Components.interfaces.nsIIOService;
  146.  
  147.         var loader = Components.classes[jssslContractID].getService(jssslIID);
  148.         var dirsvc = Components.classes[dirsvcContractID].getService(propsIID);
  149.         var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
  150.  
  151.         // We expect to find the subscripts in our directory.
  152.         var appdir = __LOCATION__.parent;
  153.  
  154.         for (var i = 0; i < componentData.length; i++) {
  155.             var scriptName = componentData[i].script;
  156.             if (!scriptName)
  157.                 continue;
  158.  
  159.             var f = appdir.clone();
  160.             f.append(scriptName);
  161.  
  162.             try {
  163.                 var fileurl = iosvc.newFileURI(f);
  164.                 loader.loadSubScript(fileurl.spec, null);
  165.             } catch (e) {
  166.                 dump("Error while loading " + fileurl.spec + "\n");
  167.                 throw e;
  168.             }
  169.         }
  170.  
  171.         this.mScriptsLoaded = true;
  172.     },
  173.  
  174.     registerSelf: function (compMgr, fileSpec, location, type) {
  175.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  176.  
  177.         var catman = Components.classes["@mozilla.org/categorymanager;1"]
  178.             .getService(Components.interfaces.nsICategoryManager);
  179.         for (var i = 0; i < componentData.length; i++) {
  180.             var comp = componentData[i];
  181.             if (!comp.cid)
  182.                 continue;
  183.             dump ("calItemModule: registering " + comp.contractid + "\n");
  184.             compMgr.registerFactoryLocation(comp.cid,
  185.                                             "",
  186.                                             comp.contractid,
  187.                                             fileSpec,
  188.                                             location,
  189.                                             type);
  190.  
  191.             if (comp.category) {
  192.                 var contractid;
  193.                 if (comp.service)
  194.                     contractid = "service," + comp.contractid;
  195.                 else
  196.                     contractid = comp.contractid;
  197.                 catman.addCategoryEntry(comp.category, comp.categoryEntry,
  198.                                         contractid, true, true);
  199.                 dump("registering for category stuff\n");
  200.             }
  201.         }
  202.     },
  203.  
  204.     makeFactoryFor: function(constructor) {
  205.         var factory = {
  206.             QueryInterface: function (aIID) {
  207.                 if (!aIID.equals(Components.interfaces.nsISupports) &&
  208.                     !aIID.equals(Components.interfaces.nsIFactory))
  209.                     throw Components.results.NS_ERROR_NO_INTERFACE;
  210.                 return this;
  211.             },
  212.  
  213.             createInstance: function (outer, iid) {
  214.                 if (outer != null)
  215.                     throw Components.results.NS_ERROR_NO_AGGREGATION;
  216.                 return (new constructor()).QueryInterface(iid);
  217.             }
  218.         };
  219.  
  220.         return factory;
  221.     },
  222.  
  223.     getClassObject: function (compMgr, cid, iid) {
  224.         if (!iid.equals(Components.interfaces.nsIFactory))
  225.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  226.  
  227.         if (!this.mScriptsLoaded)
  228.             this.loadScripts();
  229.  
  230.         if (!componentInitRun) {
  231.             initBaseComponent();
  232.             componentInitRun = true;
  233.         }
  234.  
  235.         for (var i = 0; i < componentData.length; i++) {
  236.             if (cid.equals(componentData[i].cid)) {
  237.                 if (componentData[i].onComponentLoad) {
  238.                     eval(componentData[i].onComponentLoad);
  239.                 }
  240.                 // eval to get usual scope-walking
  241.                 return this.makeFactoryFor(eval(componentData[i].constructor));
  242.             }
  243.         }
  244.  
  245.         throw Components.results.NS_ERROR_NO_INTERFACE;
  246.     },
  247.  
  248.     canUnload: function(compMgr) {
  249.         return true;
  250.     }
  251. };
  252.  
  253. function NSGetModule(compMgr, fileSpec) {
  254.     return calItemModule;
  255. }
  256.