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