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, aLoginInfo)
\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 var noFocus = false;
\r
38 if(typeof targetWindow.new_tabs == 'function' && aArgument != null) {
\r
39 targetWindow.new_tabs(aArgument);
\r
42 if(typeof targetWindow.auto_login == 'function' && aLoginInfo != null) {
\r
43 targetWindow.auto_login(aLoginInfo);
\r
52 if (aArgument != null && aArgument.length != 0 || aLoginInfo != null)
\r
54 params = { "openTabs" : aArgument, "loginInfo" : aLoginInfo };
\r
55 params.wrappedJSObject = params;
\r
57 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
\r
58 getService(Components.interfaces.nsIWindowWatcher);
\r
59 ww.openWindow(null, aChromeURISpec, aName,
\r
60 "chrome,resizable,dialog=no", params);
\r
65 * The XPCOM component that implements nsICommandLineHandler.
\r
66 * It also implements nsIFactory to serve as its own singleton factory.
\r
68 const myAppHandler = {
\r
70 QueryInterface : function clh_QI(iid)
\r
72 if (iid.equals(nsICommandLineHandler) ||
\r
73 iid.equals(nsIFactory) ||
\r
74 iid.equals(nsISupports))
\r
77 throw Components.results.NS_ERROR_NO_INTERFACE;
\r
80 /* nsICommandLineHandler */
\r
82 handle : function clh_handle(cmdLine)
\r
84 // Each of these options is used for opening a new tab, either on login or remote send.
\r
85 // XULRunner does some sanitize to turn /ilsblah into -ilsblah, for example.
\r
86 // In addition to the ones here, -ilslogin, -ilsoffline, and -ilsstandalone
\r
87 // are defined below.
\r
89 // With the exception of 'new', 'tab', and 'init', the value is checked for in urls in main.js.
\r
91 // NOTE: The option itself should be all lowercase (we .toLowerCase below)
\r
93 '-ilscheckin' : 'XUL_CHECKIN',
\r
94 '-ilscheckout' : 'XUL_PATRON_BARCODE_ENTRY',
\r
95 '-ilsnew' : 'new', // 'new' is a special keyword for opening a new window
\r
96 '-ilstab' : 'tab', // 'tab' is a special keyword for opening a new tab with the default content
\r
97 '-ilsnew_default' : 'init', // 'init' is a special keyword for opening a new window with an initial default tab
\r
100 var inParams = new Array();
\r
101 var loginInfo = {};
\r
102 var loginInfoProvided = false;
\r
104 while (position < cmdLine.length) {
\r
105 var arg = cmdLine.getArgument(position).toLowerCase();
\r
106 if (options[arg] != undefined) {
\r
107 inParams.push(options[arg]);
\r
108 cmdLine.removeArguments(position,position);
\r
111 if (arg == '-ilsurl' && cmdLine.length > position) {
\r
112 inParams.push(cmdLine.getArgument(position + 1));
\r
113 cmdLine.removeArguments(position, position + 1);
\r
116 if (arg == '-ilshost' && cmdLine.length > position) {
\r
117 loginInfo.host = cmdLine.getArgument(position + 1);
\r
118 cmdLine.removeArguments(position, position + 1);
\r
119 loginInfoProvided = true;
\r
122 if (arg == '-ilsuser' && cmdLine.length > position) {
\r
123 loginInfo.user = cmdLine.getArgument(position + 1);
\r
124 cmdLine.removeArguments(position, position + 1);
\r
125 loginInfoProvided = true;
\r
128 if (arg == '-ilspassword' && cmdLine.length > position) {
\r
129 loginInfo.passwd = cmdLine.getArgument(position + 1);
\r
130 cmdLine.removeArguments(position, position + 1);
\r
131 loginInfoProvided = true;
\r
134 position=position + 1;
\r
137 if (cmdLine.handleFlag("ILSlogin", false) || inParams.length > 0 || loginInfoProvided) {
\r
138 findOrOpenWindow(WINDOW_MAIN, XUL_MAIN, '_blank', inParams, loginInfoProvided ? loginInfo : null);
\r
139 cmdLine.preventDefault = true;
\r
142 if (cmdLine.handleFlag("ILSoffline", false) || cmdLine.handleFlag("ILSstandalone", false)) {
\r
143 findOrOpenWindow(WINDOW_STANDALONE, XUL_STANDALONE, 'Offline', null, null);
\r
144 cmdLine.preventDefault = true;
\r
148 // CHANGEME: change the help info as appropriate, but
\r
149 // follow the guidelines in nsICommandLineHandler.idl
\r
150 // specifically, flag descriptions should start at
\r
151 // character 24, and lines should be wrapped at
\r
152 // 72 characters with embedded newlines,
\r
153 // and finally, the string should end with a newline
\r
154 helpInfo : " -ILScheckin Open an Evergreen checkin tab\n" +
\r
155 " -ILScheckout Open an Evergreen checkout tab\n" +
\r
156 " -ILSnew Open a new Evergreen 'menu' window\n" +
\r
157 " -ILSnew_default Open a new Evergreen 'menu' window,\n" +
\r
158 " with a 'default' tab\n" +
\r
159 " -ILStab Open a 'default' tab alone\n" +
\r
160 " -ILSurl <url> Open the specified url in an Evergreen tab\n" +
\r
161 " -ILShost Default hostname for login\n" +
\r
162 " -ILSuser Default username for login\n" +
\r
163 " -ILSpassword Default password for login\n" +
\r
164 " The above three, if all specified, trigger an automatic login attempt\n" +
\r
165 " The above nine imply -ILSlogin\n" +
\r
166 " -ILSlogin Open the Evergreen Login window\n" +
\r
167 " -ILSstandalone Open the Evergreen Standalone interface\n" +
\r
168 " -ILSoffline Alias for -ILSstandalone\n",
\r
172 createInstance : function clh_CI(outer, iid)
\r
175 throw Components.results.NS_ERROR_NO_AGGREGATION;
\r
177 return this.QueryInterface(iid);
\r
180 lockFactory : function clh_lock(lock)
\r
187 * The XPCOM glue that implements nsIModule
\r
189 const myAppHandlerModule = {
\r
191 QueryInterface : function mod_QI(iid)
\r
193 if (iid.equals(nsIModule) ||
\r
194 iid.equals(nsISupports))
\r
197 throw Components.results.NS_ERROR_NO_INTERFACE;
\r
201 getClassObject : function mod_gch(compMgr, cid, iid)
\r
203 if (cid.equals(clh_CID))
\r
204 return myAppHandler.QueryInterface(iid);
\r
206 throw Components.results.NS_ERROR_NOT_REGISTERED;
\r
209 registerSelf : function mod_regself(compMgr, fileSpec, location, type)
\r
211 compMgr.QueryInterface(nsIComponentRegistrar);
\r
213 compMgr.registerFactoryLocation(clh_CID,
\r
220 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
\r
221 getService(nsICategoryManager);
\r
222 catMan.addCategoryEntry("command-line-handler",
\r
224 clh_contractID, true, true);
\r
227 unregisterSelf : function mod_unreg(compMgr, location, type)
\r
229 compMgr.QueryInterface(nsIComponentRegistrar);
\r
230 compMgr.unregisterFactoryLocation(clh_CID, location);
\r
232 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
\r
233 getService(nsICategoryManager);
\r
234 catMan.deleteCategoryEntry("command-line-handler", clh_category);
\r
237 canUnload : function (compMgr)
\r
243 /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
\r
244 * this component provides
\r
246 function NSGetModule(comMgr, fileSpec)
\r
248 return myAppHandlerModule;
\r