00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef EXECUTABLESHELL_H 00011 #define EXECUTABLESHELL_H 00012 00013 #include "Executable.h" 00014 #include "PlugInShell.h" 00015 00016 #include <list> 00017 #include <string> 00018 #include <vector> 00019 00020 class PlugInArgList; 00021 00022 /** 00023 * \ingroup ShellModule 00024 * A base class for plug-in shells or plug-in instances. 00025 * 00026 * This class provides a default implementation of the Executable 00027 * plug-in interfaces and serves as an optional base class for specialized 00028 * plug-in shell classes and/or custom plug-ins. 00029 * 00030 * @see PlugIn, Executable 00031 */ 00032 class ExecutableShell : public Executable, public PlugInShell 00033 { 00034 public: 00035 /** 00036 * Creates the plug-in. 00037 * 00038 * The constructor initializes the plug-in as follows: 00039 * - isExecutedOnStartup() returns \b false. 00040 * - isDestroyedAfterExecute() returns \b true. 00041 * - isBatch() returns \b true. 00042 * - hasAbort() returns \b false. 00043 * - isBackground() returns \b false. 00044 * - hasWizardSupport() returns \b true. 00045 * 00046 * @see ConfigurationSettings::getVersion() 00047 */ 00048 ExecutableShell(); 00049 00050 /** 00051 * Destroys the plug-in. 00052 */ 00053 virtual ~ExecutableShell(); 00054 00055 // Executable 00056 bool isExecutedOnStartup() const; 00057 bool isDestroyedAfterExecute() const; 00058 const std::vector<std::string>& getMenuLocations() const; 00059 00060 /** 00061 * @copydoc Executable::setBatch() 00062 * 00063 * @default The default implementation sets an internal flag that can be 00064 * queried with isBatch() and returns \b true. 00065 */ 00066 bool setBatch(); 00067 00068 /** 00069 * @copydoc Executable::setInteractive() 00070 * 00071 * @default The default implementation sets an internal flag that can be 00072 * queried with isBatch() and returns \b true. 00073 */ 00074 bool setInteractive(); 00075 00076 /** 00077 * @copydoc Executable::initialize() 00078 * 00079 * @default The default implementation does nothing and returns \b true. 00080 */ 00081 bool initialize(); 00082 00083 /** 00084 * @copydoc Executable::abort() 00085 * 00086 * @default If hasAbort() returns \b true, the default implementation sets 00087 * an internal flag that can be queried with isAborted() and 00088 * returns \b true. If hasAbort() returns \b false, the default 00089 * implementation returns \b false. 00090 */ 00091 bool abort(); 00092 00093 /** 00094 * @copydoc Executable::hasAbort() 00095 * 00096 * @default The default implementation returns the value that was passed 00097 * into setAbortSupported(). If setAbortSupported() has not yet 00098 * been called, \b false is returned. 00099 */ 00100 bool hasAbort(); 00101 00102 /** 00103 * @copydoc Executable::isBackground() 00104 * 00105 * @default The default implementation returns the value that was passed 00106 * into setBackground(). If setBackground() has not yet been 00107 * called, \b false is returned. 00108 */ 00109 bool isBackground() const; 00110 00111 00112 /** 00113 * Queries whether the plug-in is set to execute in batch mode. 00114 * 00115 * @return Returns \b true if the plug-in is set to execute in batch mode 00116 * or \b false if the plug-in is set to execute in interactive 00117 * mode. 00118 * 00119 * @see setBatch(), setInteractive() 00120 */ 00121 bool isBatch() const; 00122 00123 /** 00124 * Queries whether the plug-in is in an aborting state. 00125 * 00126 * @return Returns \b true if the plug-in is currently aborting, otherwise 00127 * returns \b false. Also returns \b false if aborting is not 00128 * supported. 00129 * 00130 * @see hasAbort(), abort() 00131 */ 00132 bool isAborted() const; 00133 00134 /** 00135 * Queries whether the plug-in supports being added as a wizard item. 00136 * 00137 * @return Returns \b true if the user should be able to add this 00138 * plug-in to the wizard builder. Returns \b false if 00139 * the user should NOT be able to add this plug-in to 00140 * the wizard builder. 00141 * 00142 * @see setWizardSupported 00143 */ 00144 bool hasWizardSupport() const; 00145 00146 protected: 00147 /** 00148 * Sets whether the plug-in is automatically executed when the 00149 * application starts. 00150 * 00151 * @param bExecute 00152 * Set this value to true if the plug-in should be 00153 * automatically executed, otherwise false. 00154 */ 00155 void executeOnStartup(bool bExecute); 00156 00157 /** 00158 * Sets whether the plug-in is automatically destroyed after it is 00159 * successfully executed. Plug-ins which are not successfully executed are 00160 * automatically destroyed by the application. 00161 * 00162 * After a plug-in is successfully executed, it can be destroyed by the application 00163 * or stay resident in memory. A plug-in may need to exist after execution, 00164 * such as those containing modeless GUI components that require user 00165 * interaction or continually display data. 00166 * 00167 * @param bDestroy 00168 * Set this value to true if the plug-in should be automatically 00169 * destroyed after it is successfully executed, otherwise false. 00170 * 00171 * @see execute() 00172 */ 00173 void destroyAfterExecute(bool bDestroy); 00174 00175 /** 00176 * Sets a single menu location and command name from which the plug-in 00177 * is executed. 00178 * 00179 * This method sets the location and name of a single menu command that 00180 * is used to execute the plug-in. %Any existing menu command locations 00181 * are removed to set the given location. Additional menu commands can be 00182 * specified to execute this plug-in by calling the addMenuLocation() 00183 * method instead. 00184 * 00185 * @param menuLocation 00186 * The menu location and name of the menu commmand used to execute 00187 * the plug-in.<br><br>The string should be formatted with 00188 * brackets ([,]) to specify a toolbar and a slash (/) to indicate 00189 * submenus. The toolbar name appears first in the string, 00190 * followed by an optional slash, and then the menus, submenus and 00191 * command name separated by slashes. If the optional slash 00192 * appears following the toolbar name, this indicates that the 00193 * submenus and command should be added to the default toolbar 00194 * menu, which has the same name as the toolbar. If a slash does 00195 * not follow the toolbar name, the menus and command are added 00196 * directly to the toolbar. If the string does not include a 00197 * toolbar name, the menus and command are added to the main menu 00198 * bar. The string cannot end with a slash, and the name after 00199 * the last slash indicates the command name. An empty string 00200 * indicates that the plug-in does not have a menu location, and 00201 * that it should not be executed from the menus.<br><br> 00202 * Examples of the menu string include the following: 00203 * <ul><li>[Geo]/Georeference</li> 00204 * <li>&Tools/Flicker %Window</li></ul> 00205 * 00206 * @see addMenuLocation() 00207 */ 00208 void setMenuLocation(const std::string& menuLocation); 00209 00210 /** 00211 * Adds a menu location and command name from which the plug-in is 00212 * executed. 00213 * 00214 * This method adds an additional menu command that is used to execute the 00215 * plug-in. Derived plug-ins that call this method should specify the 00216 * following input arg in getInputSpecification(): 00217 * <ul><li>Name: "Menu Command"</li> 00218 * <li>Type: "string"</li></ul> 00219 * 00220 * When the execute() method is called, this plug-in arg in the input arg 00221 * list should be populated with the command name that was used to execute 00222 * the plug-in. 00223 * 00224 * @param menuLocation 00225 * The menu location and name of the menu commmand used to execute 00226 * the plug-in.<br><br>The string should be formatted with 00227 * brackets ([,]) to specify a toolbar and a slash (/) to indicate 00228 * submenus. The toolbar name appears first in the string, 00229 * followed by an optional slash, and then the menus, submenus and 00230 * command name separated by slashes. If the optional slash 00231 * appears following the toolbar name, this indicates that the 00232 * submenus and command should be added to the default toolbar 00233 * menu, which has the same name as the toolbar. If a slash does 00234 * not follow the toolbar name, the menus and command are added 00235 * directly to the toolbar. If the string does not include a 00236 * toolbar name, the menus and command are added to the main menu 00237 * bar. The string cannot end with a slash, and the name after 00238 * the last slash indicates the command name. An empty string 00239 * indicates that the plug-in does not have a menu location, and 00240 * that it should not be executed from the menus.<br><br> 00241 * Examples of the menu string include the following: 00242 * <ul><li>[Geo]/Georeference</li> 00243 * <li>&Tools/Flicker %Window</li></ul> 00244 * 00245 * @see setMenuLocation() 00246 */ 00247 void addMenuLocation(const std::string& menuLocation); 00248 00249 /** 00250 * Sets whether the plug-in supports aborting. 00251 * 00252 * @param bSupported 00253 * If this value is \b true, aborting is enabled and the default 00254 * implementation of hasAbort() will return \b true. If this 00255 * value is \b false, aborting is disabled and the default 00256 * implementation of hasAbort() will return \b false. 00257 */ 00258 void setAbortSupported(bool bSupported); 00259 00260 /** 00261 * Sets whether the plug-in performs background processing. 00262 * 00263 * @param bBackground 00264 * If this value is \b true, the plug-in is set to perform 00265 * background processing. Destruction and possible unloading of 00266 * the plug-in will be delayed until the plug-in indicates that 00267 * background processing has ended. 00268 * 00269 * @see isBackground(), DesktopServices::registerCallback() 00270 */ 00271 void setBackground(bool bBackground); 00272 00273 /** 00274 * Sets whether the plug-in supports being added to a wizard. 00275 * 00276 * @param bSupported 00277 * If this value is \b true, then a user will 00278 * be able to add this plug-in to a wizard in the wizard builder. 00279 * If this value is \b false, then a user will 00280 * not be able to add this plug-in to a wizard 00281 * in the wizard builder. 00282 * 00283 * @see hasWizardSupport() 00284 */ 00285 void setWizardSupported(bool bSupported); 00286 00287 /** 00288 * Set to \c true if the plug-in has been aborted. 00289 * 00290 * Subclasses should typically use isAborted(). This is 00291 * only made available for the case where a pointer or reference 00292 * to an abort flag is passed into other code. 00293 */ 00294 mutable bool mAborted; 00295 00296 private: 00297 bool mExecuteOnStartup; 00298 bool mDestroyAfterExecute; 00299 std::vector<std::string> mMenuLocations; 00300 bool mBatch; 00301 bool mHasAbort; 00302 bool mBackground; 00303 bool mHasWizard; 00304 }; 00305 00306 #endif