Back to index

lightning-sunbird  0.9+nobinonly
nsICmdLineHandler.idl
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsISupports.idl"
00040 
00041 
00042 %{C++
00043 
00044 #define COMMAND_LINE_ARGUMENT_HANDLERS "command-line-argument-handlers"
00045 #define PREF_STARTUP_PREFIX "general.startup."
00046 
00047 #include "nsCOMPtr.h"
00048 #include "nsIComponentManager.h"
00049 #include "nsICategoryManager.h"
00050 #include "nsIFile.h"
00051 #include "nsIServiceManager.h"
00052 
00053 struct nsModuleComponentInfo;   // forward declaration
00054 
00055 #define CMDLINEHANDLER_REGISTERPROC_DECLS \
00056 static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info);  \
00057 static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info);
00058 
00059 #define CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\
00060 NS_IMETHODIMP macro_class::GetDefaultArgs(PRUnichar **aDefaultArgs) \
00061 { \
00062     if (!aDefaultArgs) return NS_ERROR_FAILURE; \
00063     *aDefaultArgs = ToNewUnicode(nsDependentCString(macro_default_args)); \
00064     return NS_OK; \
00065 }
00066 
00067 #define CMDLINEHANDLER_GETCHROMEURL_IMPL(macro_class,macro_chrome_url)\
00068 NS_IMETHODIMP macro_class::GetChromeUrlForTask(char **aChromeUrlForTask) \
00069 { \
00070     if (!aChromeUrlForTask) return NS_ERROR_FAILURE; \
00071     *aChromeUrlForTask = PL_strdup(macro_chrome_url); \
00072     return NS_OK; \
00073 }
00074 
00075 #define CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,macro_help_text, macro_handles_args, macro_open_window_with_args)\
00076 NS_IMETHODIMP macro_class::GetCommandLineArgument(char **aCommandLineArgument) \
00077 { \
00078     if (!aCommandLineArgument) return NS_ERROR_FAILURE; \
00079     *aCommandLineArgument = PL_strdup(macro_cmd_line_arg); \
00080     return NS_OK; \
00081 } \
00082 NS_IMETHODIMP macro_class::GetPrefNameForStartup(char **aPrefNameForStartup) \
00083 { \
00084     if (!aPrefNameForStartup) return NS_ERROR_FAILURE; \
00085     *aPrefNameForStartup = PL_strdup(macro_pref_name); \
00086     return NS_OK; \
00087 } \
00088 NS_IMETHODIMP macro_class::GetHelpText(char **aHelpText) \
00089 { \
00090     if (!aHelpText) return NS_ERROR_FAILURE; \
00091     *aHelpText = PL_strdup(macro_help_text); \
00092     return NS_OK; \
00093 } \
00094 NS_IMETHODIMP macro_class::GetHandlesArgs(PRBool *aHandlesArgs) \
00095 { \
00096     if (!aHandlesArgs) return NS_ERROR_FAILURE; \
00097     *aHandlesArgs = macro_handles_args; \
00098     return NS_OK; \
00099 } \
00100 NS_IMETHODIMP macro_class::GetOpenWindowWithArgs(PRBool *aOpenWindowWithArgs) \
00101 { \
00102     if (!aOpenWindowWithArgs) return NS_ERROR_FAILURE; \
00103     *aOpenWindowWithArgs = macro_open_window_with_args; \
00104     return NS_OK; \
00105 }
00106 
00107 #define CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, \
00108                                          macro_pretty_name, \
00109                                          macro_contractid) \
00110 NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info) \
00111 { \
00112     nsresult rv; \
00113     nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \
00114     if (NS_FAILED(rv)) return rv; \
00115     nsXPIDLCString prevEntry; \
00116     rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_pretty_name, macro_contractid, PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); \
00117        return NS_OK; \
00118 } \
00119 NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info) \
00120 { \
00121     nsresult rv; \
00122     nsCOMPtr<nsICategoryManager> catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \
00123     if (NS_FAILED(rv)) return rv; \
00124     rv = catman->DeleteCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_contractid, PR_TRUE); \
00125     return NS_OK; \
00126 }
00127 
00128 // basic definition
00129 #define CMDLINEHANDLER1_IMPL(macro_class, \
00130                              macro_cmd_line_arg, \
00131                              macro_pref_name, \
00132                              macro_help_text, \
00133                              macro_handles_args, \
00134                              macro_default_args, \
00135                              macro_open_window_with_args)\
00136 CMDLINEHANDLER_OTHERS_IMPL(macro_class, macro_cmd_line_arg,macro_pref_name,\
00137                            macro_help_text, macro_handles_args, \
00138                            macro_open_window_with_args)
00139 
00140 // provides everything above, plus GetChromeUrl and regproc stuff
00141 #define CMDLINEHANDLER2_IMPL(macro_class, \
00142                              macro_cmd_line_arg, \
00143                              macro_pref_name, \
00144                              macro_chrome_url, \
00145                              macro_help_text, \
00146                              macro_contractid, \
00147                              macro_pretty_name, \
00148                              macro_handles_args, \
00149                              macro_open_window_with_args) \
00150 CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,\
00151                            macro_help_text, macro_handles_args, \
00152                            macro_open_window_with_args) \
00153 CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, macro_pretty_name, \
00154                                  macro_contractid) \
00155 CMDLINEHANDLER_GETCHROMEURL_IMPL(macro_class,macro_chrome_url)
00156 
00157 // deprecated: includes everything above, plus getdefaultargs
00158 #define CMDLINEHANDLER_IMPL(macro_class, \
00159                             macro_cmd_line_arg,\
00160                             macro_pref_name, \
00161                             macro_chrome_url,\
00162                             macro_help_text, \
00163                             macro_contractid, \
00164                             macro_pretty_name, \
00165                             macro_handles_args, \
00166                             macro_default_args, \
00167                             macro_open_window_with_args) \
00168 CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args) \
00169 CMDLINEHANDLER2_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name, \
00170                      macro_chrome_url,macro_help_text, macro_contractid, \
00171                      macro_pretty_name, macro_handles_args, \
00172                      macro_open_window_with_args)
00173 
00174 //Creates a version without the GetChromeUrlForTaskFunction
00175 #define CMDLINEHANDLER3_IMPL(macro_class, \
00176                              macro_cmd_line_arg, \
00177                              macro_pref_name, \
00178                              macro_help_text, \
00179                              macro_contractid, \
00180                              macro_pretty_name, \
00181                              macro_handles_args, \
00182                              macro_default_args, \
00183                              macro_open_window_with_args)\
00184 CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\
00185 CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,\
00186                            macro_help_text, macro_handles_args, \
00187                            macro_open_window_with_args) \
00188 CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, macro_pretty_name, \
00189                                     macro_contractid)
00190 
00191 %}
00192 
00193 [scriptable, uuid(ae12670a-1dd1-11b2-80cd-82ec93559deb)]
00194 interface nsICmdLineHandler : nsISupports
00195 {
00196     readonly attribute string commandLineArgument;
00197     readonly attribute string prefNameForStartup;
00198     readonly attribute string chromeUrlForTask;
00199     readonly attribute string helpText;
00200 
00201     readonly attribute boolean handlesArgs;
00202     readonly attribute wstring defaultArgs;
00203     readonly attribute boolean openWindowWithArgs;
00204 };
00205