1 const nsISupports = Components.interfaces.nsISupports;
\r
2 const nsICategoryManager = Components.interfaces.nsICategoryManager;
\r
3 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
\r
4 const nsICommandLine = Components.interfaces.nsICommandLine;
\r
5 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
\r
6 const nsIFactory = Components.interfaces.nsIFactory;
\r
7 const nsIModule = Components.interfaces.nsIModule;
\r
8 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
\r
11 const XUL_STANDALONE = "chrome://open_ils_staff_client/content/circ/offline.xul";
\r
12 const XUL_MAIN = "chrome://open_ils_staff_client/content/main/main.xul";
\r
13 const WINDOW_STANDALONE = "eg_offline"
\r
14 const WINDOW_MAIN = "eg_main"
\r
16 const clh_contractID = "@mozilla.org/commandlinehandler/general-startup;1?type=egcli";
\r
17 const clh_CID = Components.ID("{7e608198-7355-483a-a85a-20322e4ef91a}");
\r
18 // category names are sorted alphabetically. Typical command-line handlers use a
\r
19 // category that begins with the letter "m".
\r
20 const clh_category = "m-egcli";
\r
27 * Opens a chrome window.
\r
28 * @param aChromeURISpec a string specifying the URI of the window to open.
\r
29 * @param aArgument an argument to pass to the window (may be null)
\r
31 function findOrOpenWindow(aWindowType, aChromeURISpec, aName, aArgument)
\r
33 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
\r
34 getService(Components.interfaces.nsIWindowMediator);
\r
35 var targetWindow = wm.getMostRecentWindow(aWindowType);
\r
36 if (targetWindow != null) {
\r
37 if(typeof targetWindow.new_tabs == 'function' && aArgument != null)
\r
39 targetWindow.new_tabs(aArgument);
\r
47 if (aArgument != null && aArgument.length != 0)
\r
49 params = { "openTabs" : aArgument };
\r
50 params.wrappedJSObject = params;
\r
52 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
\r
53 getService(Components.interfaces.nsIWindowWatcher);
\r
54 ww.openWindow(null, aChromeURISpec, aName,
\r
55 "chrome,resizable,dialog=no", params);
\r
60 * The XPCOM component that implements nsICommandLineHandler.
\r
61 * It also implements nsIFactory to serve as its own singleton factory.
\r
63 const myAppHandler = {
\r
65 QueryInterface : function clh_QI(iid)
\r
67 if (iid.equals(nsICommandLineHandler) ||
\r
68 iid.equals(nsIFactory) ||
\r
69 iid.equals(nsISupports))
\r
72 throw Components.results.NS_ERROR_NO_INTERFACE;
\r
75 /* nsICommandLineHandler */
\r
77 handle : function clh_handle(cmdLine)
\r
79 // Each of these options is used for opening a new tab, either on login or remote send.
\r
80 // XULRunner does some sanitize to turn /ilsblah into -ilsblah, for example.
\r
81 // In addition to the ones here, -ilslogin, -ilsoffline, and -ilsstandalone
\r
82 // are defined below.
\r
84 // With the exception of 'new', 'tab', and 'init', the value is checked for in urls in main.js.
\r
86 // NOTE: The option itself should be all lowercase (we .toLowerCase below)
\r
88 '-ilscheckin' : 'XUL_CHECKIN',
\r
89 '-ilscheckout' : 'XUL_PATRON_BARCODE_ENTRY',
\r
90 '-ilsnew' : 'new', // 'new' is a special keyword for opening a new window
\r
91 '-ilstab' : 'tab', // 'tab' is a special keyword for opening a new tab with the default content
\r
92 '-ilsnew_default' : 'init', // 'init' is a special keyword for opening a new window with an initial default tab
\r
95 var inParams = new Array();
\r
97 while (position < cmdLine.length) {
\r
98 var arg = cmdLine.getArgument(position).toLowerCase();
\r
99 if (options[arg] != undefined) {
\r
100 inParams.push(options[arg]);
\r
101 cmdLine.removeArguments(position,position);
\r
104 if (arg == '-ilsurl' && cmdLine.length > position) {
\r
105 inParams.push(cmdLine.getArgument(position + 1));
\r
106 cmdLine.removeArguments(position, position + 1);
\r
109 position=position + 1;
\r
112 if (cmdLine.handleFlag("ILSlogin", false) || inParams.length > 0) {
\r
113 findOrOpenWindow(WINDOW_MAIN, XUL_MAIN, '_blank', inParams);
\r
114 cmdLine.preventDefault = true;
\r
117 if (cmdLine.handleFlag("ILSoffline", false) || cmdLine.handleFlag("ILSstandalone", false)) {
\r
118 findOrOpenWindow(WINDOW_STANDALONE, XUL_STANDALONE, 'Offline', null);
\r
119 cmdLine.preventDefault = true;
\r
123 // CHANGEME: change the help info as appropriate, but
\r
124 // follow the guidelines in nsICommandLineHandler.idl
\r
125 // specifically, flag descriptions should start at
\r
126 // character 24, and lines should be wrapped at
\r
127 // 72 characters with embedded newlines,
\r
128 // and finally, the string should end with a newline
\r
129 helpInfo : " -ILScheckin Open an Evergreen checkin tab\n" +
\r
130 " -ILScheckout Open an Evergreen checkout tab\n" +
\r
131 " -ILSnew Open a new Evergreen 'menu' window\n" +
\r
132 " -ILSnew_default Open a new Evergreen 'menu' window,\n" +
\r
133 " with a 'default' tab\n" +
\r
134 " -ILStab Open a 'default' tab alone\n" +
\r
135 " -ILSurl <url> Open the specified url in an Evergreen tab\n" +
\r
136 " The above six imply -ILSlogin\n" +
\r
137 " -ILSlogin Open the Evergreen Login window\n" +
\r
138 " -ILSstandalone Open the Evergreen Standalone interface\n" +
\r
139 " -ILSoffline Alias for -ILSstandalone\n",
\r
143 createInstance : function clh_CI(outer, iid)
\r
146 throw Components.results.NS_ERROR_NO_AGGREGATION;
\r
148 return this.QueryInterface(iid);
\r
151 lockFactory : function clh_lock(lock)
\r
158 * The XPCOM glue that implements nsIModule
\r
160 const myAppHandlerModule = {
\r
162 QueryInterface : function mod_QI(iid)
\r
164 if (iid.equals(nsIModule) ||
\r
165 iid.equals(nsISupports))
\r
168 throw Components.results.NS_ERROR_NO_INTERFACE;
\r
172 getClassObject : function mod_gch(compMgr, cid, iid)
\r
174 if (cid.equals(clh_CID))
\r
175 return myAppHandler.QueryInterface(iid);
\r
177 throw Components.results.NS_ERROR_NOT_REGISTERED;
\r
180 registerSelf : function mod_regself(compMgr, fileSpec, location, type)
\r
182 compMgr.QueryInterface(nsIComponentRegistrar);
\r
184 compMgr.registerFactoryLocation(clh_CID,
\r
191 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
\r
192 getService(nsICategoryManager);
\r
193 catMan.addCategoryEntry("command-line-handler",
\r
195 clh_contractID, true, true);
\r
198 unregisterSelf : function mod_unreg(compMgr, location, type)
\r
200 compMgr.QueryInterface(nsIComponentRegistrar);
\r
201 compMgr.unregisterFactoryLocation(clh_CID, location);
\r
203 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
\r
204 getService(nsICategoryManager);
\r
205 catMan.deleteCategoryEntry("command-line-handler", clh_category);
\r
208 canUnload : function (compMgr)
\r
214 /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
\r
215 * this component provides
\r
217 function NSGetModule(comMgr, fileSpec)
\r
219 return myAppHandlerModule;
\r