home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 May / PCWorld_2008-05_cd.bin / komunikace / sameplace / sameplace-suite-release.xpi / sameplace-0.9.1.xpi / components / CommandLine.js next >
Text File  |  2008-02-11  |  3KB  |  95 lines

  1. const CATEGORY = 'c-sameplace';
  2. const CONTRACT_ID = '@mozilla.org/commandlinehandler/general-startup;1?type=sameplace';
  3.  
  4.  
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7. const Cr = Components.results;
  8. const CLASS_ID = Components.ID('{2991c315-b871-42cd-b33f-bfee4fcbf682}');
  9.  
  10. const Handler = {
  11.     QueryInterface: function(iid) {
  12.         if(iid.equals(Ci.nsICommandLineHandler) ||
  13.            iid.equals(Ci.nsIFactory) ||
  14.            iid.equals(Ci.nsISupports))
  15.             return this;
  16.  
  17.         throw Cr.NS_ERROR_NO_INTERFACE;
  18.     },
  19.  
  20.     handle: function(cmdLine) {
  21.         var uri;
  22.         try {
  23.             uri = cmdLine.handleFlagWithParam('sameplace', false);
  24.         } catch (e) {
  25.         }
  26.  
  27.         if(uri || cmdLine.handleFlag('sameplace', false)) {
  28.             var windowWatcher = Cc['@mozilla.org/embedcomp/window-watcher;1']
  29.             .getService(Ci.nsIWindowWatcher);
  30.             
  31.             windowWatcher.openWindow(
  32.                 null, 'chrome://sameplace/content/standalone/contacts.xul',
  33.                 'SamePlace:Contacts', 'chrome,toolbar=no', null)
  34.  
  35.             cmdLine.preventDefault = true;
  36.         }
  37.     },
  38.  
  39.     helpInfo: '-sameplace              Start SamePlace.\n',
  40.  
  41.     createInstance: function(outer, iid) {
  42.         if(outer != null)
  43.             throw Cr.NS_ERROR_NO_AGGREGATION;
  44.  
  45.         return this.QueryInterface(iid);
  46.     },
  47.  
  48.     lockFactory: function(lock) {
  49.         /* no-op */
  50.     }
  51. };
  52.  
  53.  
  54. const Module = {
  55.     QueryInterface: function(iid) {
  56.         if(iid.equals(Ci.nsIModule) ||
  57.            iid.equals(Ci.nsISupports))
  58.             return this;
  59.  
  60.         throw Cr.NS_ERROR_NO_INTERFACE;
  61.     },
  62.  
  63.     getClassObject: function(compMgr, cid, iid) {
  64.         if(cid.equals(CLASS_ID))
  65.             return Handler.QueryInterface(iid);
  66.  
  67.         throw Cr.NS_ERROR_NOT_REGISTERED;
  68.     },
  69.  
  70.     registerSelf: function(compMgr, fileSpec, location, type) {
  71.         compMgr.QueryInterface(Ci.nsIComponentRegistrar);
  72.         compMgr.registerFactoryLocation(CLASS_ID, 'Handler', CONTRACT_ID, fileSpec, location, type);
  73.  
  74.         var catMan = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
  75.         catMan.addCategoryEntry('command-line-handler', CATEGORY, CONTRACT_ID, true, true);
  76.     },
  77.  
  78.     unregisterSelf: function mod_unreg(compMgr, location, type) {
  79.         compMgr.QueryInterface(Ci.nsIComponentRegistrar);
  80.         compMgr.unregisterFactoryLocation(CLASS_ID, location);
  81.  
  82.         var catMan = Cc['@mozilla.org/categorymanager;1'].getService(Ci.nsICategoryManager);
  83.         catMan.deleteCategoryEntry('command-line-handler', CATEGORY);
  84.     },
  85.  
  86.     canUnload: function (compMgr) {
  87.         return true;
  88.     }
  89. };
  90.  
  91. function NSGetModule(comMgr, fileSpec) {
  92.     return Module;
  93. }
  94.  
  95.