xref: /trunk/main/desktop/source/app/cmdlineargs.hxx (revision 85c309d6)
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_CONVERSIONMODE,
47             CMD_BOOLPARAM_QUICKSTART,
48             CMD_BOOLPARAM_NOQUICKSTART,
49             CMD_BOOLPARAM_TERMINATEAFTERINIT,
50             CMD_BOOLPARAM_NOFIRSTSTARTWIZARD,
51             CMD_BOOLPARAM_NOLOGO,
52             CMD_BOOLPARAM_NOLOCKCHECK,
53             CMD_BOOLPARAM_NODEFAULT,
54             CMD_BOOLPARAM_HELP,
55             CMD_BOOLPARAM_WRITER,
56             CMD_BOOLPARAM_CALC,
57             CMD_BOOLPARAM_DRAW,
58             CMD_BOOLPARAM_IMPRESS,
59             CMD_BOOLPARAM_GLOBAL,
60             CMD_BOOLPARAM_MATH,
61             CMD_BOOLPARAM_WEB,
62             CMD_BOOLPARAM_BASE,
63             CMD_BOOLPARAM_HELPWRITER,
64             CMD_BOOLPARAM_HELPCALC,
65             CMD_BOOLPARAM_HELPDRAW,
66             CMD_BOOLPARAM_HELPBASIC,
67             CMD_BOOLPARAM_HELPMATH,
68             CMD_BOOLPARAM_HELPIMPRESS,
69             CMD_BOOLPARAM_HELPBASE,
70             CMD_BOOLPARAM_PSN,
71             CMD_BOOLPARAM_COUNT // must be last element!
72         };
73 
74         enum StringParam // must be zero based!
75         {
76             CMD_STRINGPARAM_PORTAL,
77             CMD_STRINGPARAM_ACCEPT,
78             CMD_STRINGPARAM_UNACCEPT,
79             CMD_STRINGPARAM_USERDIR,
80             CMD_STRINGPARAM_CLIENTDISPLAY,
81             CMD_STRINGPARAM_OPENLIST,
82             CMD_STRINGPARAM_VIEWLIST,
83             CMD_STRINGPARAM_STARTLIST,
84             CMD_STRINGPARAM_FORCEOPENLIST,
85             CMD_STRINGPARAM_FORCENEWLIST,
86             CMD_STRINGPARAM_PRINTLIST,
87             CMD_STRINGPARAM_VERSION,
88             CMD_STRINGPARAM_PRINTTOLIST,
89             CMD_STRINGPARAM_PRINTERNAME,
90             CMD_STRINGPARAM_DISPLAY,
91             CMD_STRINGPARAM_LANGUAGE,
92             CMD_STRINGPARAM_COUNT // must be last element!
93         };
94 
95         enum GroupParamId
96         {
97             CMD_GRPID_MODULE,
98             CMD_GRPID_COUNT
99         };
100 
101         struct Supplier
102         {
103             // Thrown from constructors and next:
104             class Exception {
105             public:
106                 Exception();
107                 Exception(Exception const &);
108                 virtual ~Exception();
109                 Exception & operator =(Exception const &);
110             };
111 
112             virtual ~Supplier();
113             virtual boost::optional< rtl::OUString > getCwdUrl() = 0;
114             virtual bool next(rtl::OUString * argument) = 0;
115         };
116 
117         CommandLineArgs();
118         CommandLineArgs( Supplier& supplier );
119 
getCwdUrl() const120         boost::optional< rtl::OUString > getCwdUrl() const { return m_cwdUrl; }
121 
122         // generic methods to access parameter
123         void     SetBoolParam( BoolParam eParam, sal_Bool bNewValue );
124 
125         // Access to bool parameters
126         sal_Bool IsMinimized() const;
127         sal_Bool IsInvisible() const;
128         sal_Bool IsNoRestore() const;
129         sal_Bool IsNoDefault() const;
130         sal_Bool IsBean() const;
131         sal_Bool IsServer() const;
132         sal_Bool IsHeadless() const;
133         sal_Bool IsConversionMode() const;
134         sal_Bool IsQuickstart() const;
135         sal_Bool IsNoQuickstart() const;
136         sal_Bool IsTerminateAfterInit() const;
137         sal_Bool IsNoFirstStartWizard() const;
138         sal_Bool IsNoLogo() const;
139         sal_Bool IsNoLockcheck() const;
140         sal_Bool IsHelp() const;
141         sal_Bool IsHelpWriter() const;
142         sal_Bool IsHelpCalc() const;
143         sal_Bool IsHelpDraw() const;
144         sal_Bool IsHelpImpress() const;
145         sal_Bool IsHelpBase() const;
146         sal_Bool IsHelpMath() const;
147         sal_Bool IsHelpBasic() const;
148         sal_Bool IsWriter() const;
149         sal_Bool IsCalc() const;
150         sal_Bool IsDraw() const;
151         sal_Bool IsImpress() const;
152         sal_Bool IsBase() const;
153         sal_Bool IsGlobal() const;
154         sal_Bool IsMath() const;
155         sal_Bool IsWeb() const;
156         sal_Bool HasModuleParam() const;
157         sal_Bool WantsToLoadDocument() const;
158 
159         // Access to string parameters
160         sal_Bool GetPortalConnectString( ::rtl::OUString& rPara) const;
161         sal_Bool GetAcceptString( ::rtl::OUString& rPara) const;
162         sal_Bool GetUnAcceptString( ::rtl::OUString& rPara) const;
163         sal_Bool GetOpenList( ::rtl::OUString& rPara) const;
164         sal_Bool GetViewList( ::rtl::OUString& rPara) const;
165         sal_Bool GetStartList( ::rtl::OUString& rPara) const;
166         sal_Bool GetForceOpenList( ::rtl::OUString& rPara) const;
167         sal_Bool GetForceNewList( ::rtl::OUString& rPara) const;
168         sal_Bool GetPrintList( ::rtl::OUString& rPara) const;
169         sal_Bool GetPrintToList( ::rtl::OUString& rPara ) const;
170         sal_Bool GetPrinterName( ::rtl::OUString& rPara ) const;
171         sal_Bool GetLanguage( ::rtl::OUString& rPara ) const;
172 
173         // Special analyzed states (does not match directly to a command line parameter!)
174         sal_Bool IsPrinting() const;
175         sal_Bool IsEmpty() const;
176         sal_Bool IsEmptyOrAcceptOnly() const;
177 
178     private:
179         enum Count { NONE, ONE, MANY };
180 
181         struct GroupDefinition
182         {
183             sal_Int32  nCount;
184             BoolParam* pGroupMembers;
185         };
186 
187         // no copy and operator=
188         CommandLineArgs( const CommandLineArgs& );
189         CommandLineArgs operator=( const CommandLineArgs& );
190 
191         sal_Bool InterpretCommandLineParameter( const ::rtl::OUString& );
192         void     ParseCommandLine_Impl( Supplier& supplier );
193         void     ResetParamValues();
194         sal_Bool CheckGroupMembers( GroupParamId nGroup, BoolParam nExcludeMember ) const;
195 
196         void     AddStringListParam_Impl( StringParam eParam, const rtl::OUString& aParam );
197         void     SetBoolParam_Impl( BoolParam eParam, sal_Bool bValue );
198 
199         boost::optional< rtl::OUString > m_cwdUrl;
200         sal_Bool                         m_aBoolParams[ CMD_BOOLPARAM_COUNT ];     // Stores boolean parameters
201         rtl::OUString                    m_aStrParams[ CMD_STRINGPARAM_COUNT ];    // Stores string parameters
202         sal_Bool                         m_aStrSetParams[ CMD_STRINGPARAM_COUNT ]; // Stores if string parameters are provided on cmdline
203         Count                            m_eArgumentCount;                         // Number of Args
204         bool                             m_bDocumentArgs;                          // A document creation/open/load arg is used
205         mutable ::osl::Mutex             m_aMutex;
206 
207         // static definition for groups where only one member can be true
208         static GroupDefinition  m_pGroupDefinitions[ CMD_GRPID_COUNT ];
209 };
210 
211 }
212 
213 #endif
214