1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _DESKTOP_COMMANDLINEARGS_HXX_ 25 #define _DESKTOP_COMMANDLINEARGS_HXX_ 26 27 #include <rtl/ustring.hxx> 28 #include <osl/mutex.hxx> 29 #include "boost/optional.hpp" 30 31 namespace desktop 32 { 33 34 class CommandLineArgs 35 { 36 public: 37 enum BoolParam // must be zero based! 38 { 39 CMD_BOOLPARAM_MINIMIZED, 40 CMD_BOOLPARAM_INVISIBLE, 41 CMD_BOOLPARAM_NORESTORE, 42 CMD_BOOLPARAM_BEAN, 43 CMD_BOOLPARAM_PLUGIN, 44 CMD_BOOLPARAM_SERVER, 45 CMD_BOOLPARAM_HEADLESS, 46 CMD_BOOLPARAM_QUICKSTART, 47 CMD_BOOLPARAM_NOQUICKSTART, 48 CMD_BOOLPARAM_TERMINATEAFTERINIT, 49 CMD_BOOLPARAM_NOFIRSTSTARTWIZARD, 50 CMD_BOOLPARAM_NOLOGO, 51 CMD_BOOLPARAM_NOLOCKCHECK, 52 CMD_BOOLPARAM_NODEFAULT, 53 CMD_BOOLPARAM_HELP, 54 CMD_BOOLPARAM_WRITER, 55 CMD_BOOLPARAM_CALC, 56 CMD_BOOLPARAM_DRAW, 57 CMD_BOOLPARAM_IMPRESS, 58 CMD_BOOLPARAM_GLOBAL, 59 CMD_BOOLPARAM_MATH, 60 CMD_BOOLPARAM_WEB, 61 CMD_BOOLPARAM_BASE, 62 CMD_BOOLPARAM_HELPWRITER, 63 CMD_BOOLPARAM_HELPCALC, 64 CMD_BOOLPARAM_HELPDRAW, 65 CMD_BOOLPARAM_HELPBASIC, 66 CMD_BOOLPARAM_HELPMATH, 67 CMD_BOOLPARAM_HELPIMPRESS, 68 CMD_BOOLPARAM_HELPBASE, 69 CMD_BOOLPARAM_PSN, 70 CMD_BOOLPARAM_COUNT // must be last element! 71 }; 72 73 enum StringParam // must be zero based! 74 { 75 CMD_STRINGPARAM_PORTAL, 76 CMD_STRINGPARAM_ACCEPT, 77 CMD_STRINGPARAM_UNACCEPT, 78 CMD_STRINGPARAM_USERDIR, 79 CMD_STRINGPARAM_CLIENTDISPLAY, 80 CMD_STRINGPARAM_OPENLIST, 81 CMD_STRINGPARAM_VIEWLIST, 82 CMD_STRINGPARAM_STARTLIST, 83 CMD_STRINGPARAM_FORCEOPENLIST, 84 CMD_STRINGPARAM_FORCENEWLIST, 85 CMD_STRINGPARAM_PRINTLIST, 86 CMD_STRINGPARAM_VERSION, 87 CMD_STRINGPARAM_PRINTTOLIST, 88 CMD_STRINGPARAM_PRINTERNAME, 89 CMD_STRINGPARAM_DISPLAY, 90 CMD_STRINGPARAM_LANGUAGE, 91 CMD_STRINGPARAM_COUNT // must be last element! 92 }; 93 94 enum GroupParamId 95 { 96 CMD_GRPID_MODULE, 97 CMD_GRPID_COUNT 98 }; 99 100 struct Supplier 101 { 102 // Thrown from constructors and next: 103 class Exception { 104 public: 105 Exception(); 106 Exception(Exception const &); 107 virtual ~Exception(); 108 Exception & operator =(Exception const &); 109 }; 110 111 virtual ~Supplier(); 112 virtual boost::optional< rtl::OUString > getCwdUrl() = 0; 113 virtual bool next(rtl::OUString * argument) = 0; 114 }; 115 116 CommandLineArgs(); 117 CommandLineArgs( Supplier& supplier ); 118 119 boost::optional< rtl::OUString > getCwdUrl() const { return m_cwdUrl; } 120 121 // generic methods to access parameter 122 void SetBoolParam( BoolParam eParam, sal_Bool bNewValue ); 123 124 // Access to bool parameters 125 sal_Bool IsMinimized() const; 126 sal_Bool IsInvisible() const; 127 sal_Bool IsNoRestore() const; 128 sal_Bool IsNoDefault() const; 129 sal_Bool IsBean() const; 130 sal_Bool IsServer() const; 131 sal_Bool IsHeadless() const; 132 sal_Bool IsQuickstart() const; 133 sal_Bool IsNoQuickstart() const; 134 sal_Bool IsTerminateAfterInit() const; 135 sal_Bool IsNoFirstStartWizard() const; 136 sal_Bool IsNoLogo() const; 137 sal_Bool IsNoLockcheck() const; 138 sal_Bool IsHelp() const; 139 sal_Bool IsHelpWriter() const; 140 sal_Bool IsHelpCalc() const; 141 sal_Bool IsHelpDraw() const; 142 sal_Bool IsHelpImpress() const; 143 sal_Bool IsHelpBase() const; 144 sal_Bool IsHelpMath() const; 145 sal_Bool IsHelpBasic() const; 146 sal_Bool IsWriter() const; 147 sal_Bool IsCalc() const; 148 sal_Bool IsDraw() const; 149 sal_Bool IsImpress() const; 150 sal_Bool IsBase() const; 151 sal_Bool IsGlobal() const; 152 sal_Bool IsMath() const; 153 sal_Bool IsWeb() const; 154 sal_Bool HasModuleParam() const; 155 sal_Bool WantsToLoadDocument() const; 156 157 // Access to string parameters 158 sal_Bool GetPortalConnectString( ::rtl::OUString& rPara) const; 159 sal_Bool GetAcceptString( ::rtl::OUString& rPara) const; 160 sal_Bool GetUnAcceptString( ::rtl::OUString& rPara) const; 161 sal_Bool GetOpenList( ::rtl::OUString& rPara) const; 162 sal_Bool GetViewList( ::rtl::OUString& rPara) const; 163 sal_Bool GetStartList( ::rtl::OUString& rPara) const; 164 sal_Bool GetForceOpenList( ::rtl::OUString& rPara) const; 165 sal_Bool GetForceNewList( ::rtl::OUString& rPara) const; 166 sal_Bool GetPrintList( ::rtl::OUString& rPara) const; 167 sal_Bool GetPrintToList( ::rtl::OUString& rPara ) const; 168 sal_Bool GetPrinterName( ::rtl::OUString& rPara ) const; 169 sal_Bool GetLanguage( ::rtl::OUString& rPara ) const; 170 171 // Special analyzed states (does not match directly to a command line parameter!) 172 sal_Bool IsPrinting() const; 173 sal_Bool IsEmpty() const; 174 sal_Bool IsEmptyOrAcceptOnly() const; 175 176 private: 177 enum Count { NONE, ONE, MANY }; 178 179 struct GroupDefinition 180 { 181 sal_Int32 nCount; 182 BoolParam* pGroupMembers; 183 }; 184 185 // no copy and operator= 186 CommandLineArgs( const CommandLineArgs& ); 187 CommandLineArgs operator=( const CommandLineArgs& ); 188 189 sal_Bool InterpretCommandLineParameter( const ::rtl::OUString& ); 190 void ParseCommandLine_Impl( Supplier& supplier ); 191 void ResetParamValues(); 192 sal_Bool CheckGroupMembers( GroupParamId nGroup, BoolParam nExcludeMember ) const; 193 194 void AddStringListParam_Impl( StringParam eParam, const rtl::OUString& aParam ); 195 void SetBoolParam_Impl( BoolParam eParam, sal_Bool bValue ); 196 197 boost::optional< rtl::OUString > m_cwdUrl; 198 sal_Bool m_aBoolParams[ CMD_BOOLPARAM_COUNT ]; // Stores boolean parameters 199 rtl::OUString m_aStrParams[ CMD_STRINGPARAM_COUNT ]; // Stores string parameters 200 sal_Bool m_aStrSetParams[ CMD_STRINGPARAM_COUNT ]; // Stores if string parameters are provided on cmdline 201 Count m_eArgumentCount; // Number of Args 202 bool m_bDocumentArgs; // A document creation/open/load arg is used 203 mutable ::osl::Mutex m_aMutex; 204 205 // static definition for groups where only one member can be true 206 static GroupDefinition m_pGroupDefinitions[ CMD_GRPID_COUNT ]; 207 }; 208 209 } 210 211 #endif 212