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