xref: /aoo42x/main/desktop/source/app/cmdlineargs.cxx (revision 2722cedd)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_desktop.hxx"
26 #include <cmdlineargs.hxx>
27 #include <vcl/svapp.hxx>
28 #include <rtl/uri.hxx>
29 #include <rtl/ustring.hxx>
30 #include "rtl/process.h"
31 #include <comphelper/processfactory.hxx>
32 #include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/uno/Reference.hxx>
35 #include "tools/getprocessworkingdir.hxx"
36 
37 #include <svl/documentlockfile.hxx>
38 
39 using namespace rtl;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::uri;
42 using namespace com::sun::star::uno;
43 
44 namespace desktop
45 {
46 
47 namespace {
48 
49 class ExtCommandLineSupplier: public CommandLineArgs::Supplier {
50 public:
51     explicit ExtCommandLineSupplier():
52         m_count(rtl_getAppCommandArgCount()),
53         m_index(0)
54     {
55         rtl::OUString url;
56         if (tools::getProcessWorkingDir(&url)) {
57             m_cwdUrl.reset(url);
58         }
59     }
60 
61     virtual ~ExtCommandLineSupplier() {}
62 
63     virtual boost::optional< rtl::OUString > getCwdUrl() { return m_cwdUrl; }
64 
65     virtual bool next(rtl::OUString * argument) {
66         OSL_ASSERT(argument != NULL);
67         if (m_index < m_count) {
68             rtl_getAppCommandArg(m_index++, &argument->pData);
69             return true;
70         } else {
71             return false;
72         }
73     }
74 
75 private:
76     boost::optional< rtl::OUString > m_cwdUrl;
77     sal_uInt32 m_count;
78     sal_uInt32 m_index;
79 };
80 
81 }
82 
83 static CommandLineArgs::BoolParam aModuleGroupDefinition[] =
84 {
85 	CommandLineArgs::CMD_BOOLPARAM_WRITER,
86 	CommandLineArgs::CMD_BOOLPARAM_CALC,
87 	CommandLineArgs::CMD_BOOLPARAM_DRAW,
88 	CommandLineArgs::CMD_BOOLPARAM_IMPRESS,
89 	CommandLineArgs::CMD_BOOLPARAM_GLOBAL,
90 	CommandLineArgs::CMD_BOOLPARAM_MATH,
91 	CommandLineArgs::CMD_BOOLPARAM_WEB,
92 	CommandLineArgs::CMD_BOOLPARAM_BASE
93 };
94 
95 CommandLineArgs::GroupDefinition CommandLineArgs::m_pGroupDefinitions[ CommandLineArgs::CMD_GRPID_COUNT ] =
96 {
97 	{ 8, aModuleGroupDefinition }
98 };
99 
100 CommandLineArgs::Supplier::Exception::Exception() {}
101 
102 CommandLineArgs::Supplier::Exception::Exception(Exception const &) {}
103 
104 CommandLineArgs::Supplier::Exception::~Exception() {}
105 
106 CommandLineArgs::Supplier::Exception &
107 CommandLineArgs::Supplier::Exception::operator =(Exception const &)
108 { return *this; }
109 
110 CommandLineArgs::Supplier::~Supplier() {}
111 
112 // intialize class with command line parameters from process environment
113 CommandLineArgs::CommandLineArgs()
114 {
115 	ResetParamValues();
116     ExtCommandLineSupplier s;
117 	ParseCommandLine_Impl( s );
118 }
119 
120 CommandLineArgs::CommandLineArgs( Supplier& supplier )
121 {
122 	ResetParamValues();
123 	ParseCommandLine_Impl( supplier );
124 }
125 
126 // ----------------------------------------------------------------------------
127 
128 void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
129 {
130     m_cwdUrl = supplier.getCwdUrl();
131 	Reference<XMultiServiceFactory> xMS(comphelper::getProcessServiceFactory(), UNO_QUERY);
132 	OSL_ENSURE(xMS.is(), "CommandLineArgs: no ProcessServiceFactory.");
133 
134     Reference< XExternalUriReferenceTranslator > xTranslator(
135         xMS->createInstance(
136         OUString::createFromAscii(
137         "com.sun.star.uri.ExternalUriReferenceTranslator")),
138         UNO_QUERY);
139 
140 	// parse command line arguments
141     bool bOpenEvent(true);
142     bool bPrintEvent(false);
143     bool bViewEvent(false);
144     bool bStartEvent(false);
145     bool bPrintToEvent(false);
146     bool bPrinterName(false);
147     bool bForceOpenEvent(false);
148     bool bForceNewEvent(false);
149     bool bDisplaySpec(false);
150     bool bOpenDoc(false);
151 
152     m_eArgumentCount = NONE;
153 
154     for (;;)
155     {
156         ::rtl::OUString	aArg;
157         if ( !supplier.next( &aArg ) )
158         {
159             break;
160         }
161         // convert file URLs to internal form #112849#
162         if (aArg.indexOf(OUString::createFromAscii("file:"))==0 &&
163             xTranslator.is())
164         {
165             OUString tmp(xTranslator->translateToInternal(aArg));
166             if (tmp.getLength() > 0)
167                 aArg = tmp;
168         }
169 
170         String aArgStr = aArg;
171         if ( aArg.getLength() > 0 )
172         {
173             m_eArgumentCount = m_eArgumentCount == NONE ? ONE : MANY;
174             if ( !InterpretCommandLineParameter( aArg ))
175             {
176                 if ( aArgStr.GetChar(0) == '-' )
177                 {
178                     // handle this argument as an option
179                     if ( aArgStr.EqualsIgnoreCaseAscii( "-n" ))
180                     {
181                         // force new documents based on the following documents
182                         bForceNewEvent  = true;
183                         bOpenEvent      = false;
184                         bForceOpenEvent = false;
185                         bPrintToEvent   = false;
186                         bPrintEvent     = false;
187                         bViewEvent      = false;
188                         bStartEvent     = false;
189                         bDisplaySpec    = false;
190                     }
191                     else if ( aArgStr.EqualsIgnoreCaseAscii( "-o" ))
192                     {
193                         // force open documents regardless if they are templates or not
194                         bForceOpenEvent = true;
195                         bOpenEvent      = false;
196                         bForceNewEvent  = false;
197                         bPrintToEvent   = false;
198                         bPrintEvent     = false;
199                         bViewEvent      = false;
200                         bStartEvent     = false;
201                         bDisplaySpec    = false;
202                     }
203                     else if ( aArgStr.EqualsIgnoreCaseAscii( "-pt" ))
204                     {
205                         // Print to special printer
206                         bPrintToEvent   = true;
207                         bPrinterName    = true;
208                         bPrintEvent     = false;
209                         bOpenEvent      = false;
210                         bForceNewEvent  = false;
211                         bViewEvent      = false;
212                         bStartEvent     = false;
213                         bDisplaySpec    = false;
214                         bForceOpenEvent = false;
215                    }
216                    else if ( aArgStr.EqualsIgnoreCaseAscii( "-p" ))
217                    {
218                         // Print to default printer
219                         bPrintEvent     = true;
220                         bPrintToEvent   = false;
221                         bOpenEvent      = false;
222                         bForceNewEvent  = false;
223                         bForceOpenEvent = false;
224                         bViewEvent      = false;
225                         bStartEvent     = false;
226                         bDisplaySpec    = false;
227                    }
228                    else if ( aArgStr.EqualsIgnoreCaseAscii( "-view" ))
229                    {
230                         // open in viewmode
231                         bOpenEvent      = false;
232                         bPrintEvent     = false;
233                         bPrintToEvent   = false;
234                         bForceNewEvent  = false;
235                         bForceOpenEvent = false;
236                         bViewEvent      = true;
237                         bStartEvent     = false;
238                         bDisplaySpec    = false;
239  		    }
240                     else if ( aArgStr.EqualsIgnoreCaseAscii( "-show" ))
241                     {
242                         // open in viewmode
243                         bOpenEvent      = false;
244                         bViewEvent      = false;
245                         bStartEvent     = true;
246                         bPrintEvent     = false;
247                         bPrintToEvent   = false;
248                         bForceNewEvent  = false;
249                         bForceOpenEvent = false;
250                         bDisplaySpec    = false;
251                     }
252                     else if ( aArgStr.EqualsIgnoreCaseAscii( "-display" ))
253                     {
254                         // set display
255                         bOpenEvent      = false;
256                         bPrintEvent     = false;
257                         bForceOpenEvent = false;
258                         bPrintToEvent   = false;
259                         bForceNewEvent  = false;
260                         bViewEvent      = false;
261                         bStartEvent     = false;
262                         bDisplaySpec    = true;
263                     }
264                     else if ( aArgStr.EqualsIgnoreCaseAscii( "-language" ))
265                     {
266                         bOpenEvent      = false;
267                         bPrintEvent     = false;
268                         bForceOpenEvent = false;
269                         bPrintToEvent   = false;
270                         bForceNewEvent  = false;
271                         bViewEvent      = false;
272                         bStartEvent     = false;
273                         bDisplaySpec    = false;
274                     }
275 
276                     #ifdef MACOSX
277                     /* #i84053# ignore -psn on Mac
278                        Platform dependent #ifdef here is ugly, however this is currently
279                        the only platform dependent parameter. Should more appear
280                        we should find a better solution
281                     */
282                     else if ( aArgStr.CompareToAscii( "-psn", 4 ) == COMPARE_EQUAL )
283                     {
284                         // finder argument from MacOSX
285                         bOpenEvent      = false;
286                        	bPrintEvent     = false;
287                         bForceOpenEvent = false;
288                         bPrintToEvent   = false;
289                         bForceNewEvent  = false;
290                         bViewEvent      = false;
291                         bStartEvent     = false;
292                         bDisplaySpec    = false;
293                     }
294                     #endif
295                 }
296                 else
297                 {
298                     if ( bPrinterName && bPrintToEvent )
299                     {
300                         // first argument after "-pt" this must be the printer name
301                         AddStringListParam_Impl( CMD_STRINGPARAM_PRINTERNAME, aArgStr );
302                         bPrinterName = sal_False;
303                     }
304                     else
305                     {
306                         // handle this argument as a filename
307                         if ( bOpenEvent )
308                         {
309                             AddStringListParam_Impl( CMD_STRINGPARAM_OPENLIST, aArgStr );
310                             bOpenDoc = true;
311                         }
312                         else if ( bViewEvent )
313 	                {
314                             AddStringListParam_Impl( CMD_STRINGPARAM_VIEWLIST, aArgStr );
315                             bOpenDoc = true;
316                         }
317                         else if ( bStartEvent )
318                         {
319                             AddStringListParam_Impl( CMD_STRINGPARAM_STARTLIST, aArgStr );
320                             bOpenDoc = true;
321                         }
322                         else if ( bPrintEvent )
323                         {
324                             AddStringListParam_Impl( CMD_STRINGPARAM_PRINTLIST, aArgStr );
325                             bOpenDoc = true;
326                         }
327                         else if ( bPrintToEvent )
328                         {
329                             AddStringListParam_Impl( CMD_STRINGPARAM_PRINTTOLIST, aArgStr );
330                             bOpenDoc = true;
331                         }
332                         else if ( bForceNewEvent )
333                         {
334                             AddStringListParam_Impl( CMD_STRINGPARAM_FORCENEWLIST, aArgStr );
335                             bOpenDoc = true;
336                         }
337                         else if ( bForceOpenEvent )
338                         {
339                             AddStringListParam_Impl( CMD_STRINGPARAM_FORCEOPENLIST, aArgStr );
340                             bOpenDoc = true;
341                         }
342                         else if ( bDisplaySpec )
343                         {
344                             AddStringListParam_Impl( CMD_STRINGPARAM_DISPLAY, aArgStr );
345                             bDisplaySpec = false; // only one display, not a lsit
346                             bOpenEvent = true;    // set back to standard
347                         }
348                     }
349                 }
350             }
351         }
352     }
353 
354     if ( bOpenDoc )
355         m_bDocumentArgs = true;
356 }
357 
358 void CommandLineArgs::AddStringListParam_Impl( StringParam eParam, const rtl::OUString& aParam )
359 {
360 	OSL_ASSERT( eParam >= 0 && eParam < CMD_STRINGPARAM_COUNT );
361 	if ( m_aStrParams[eParam].getLength() )
362 		m_aStrParams[eParam] += ::rtl::OUString::valueOf( (sal_Unicode)APPEVENT_PARAM_DELIMITER );
363 	m_aStrParams[eParam] += aParam;
364 	m_aStrSetParams[eParam] = sal_True;
365 }
366 
367 void CommandLineArgs::SetBoolParam_Impl( BoolParam eParam, sal_Bool bValue )
368 {
369 	OSL_ASSERT( eParam >= 0 && eParam < CMD_BOOLPARAM_COUNT );
370 	m_aBoolParams[eParam] = bValue;
371 }
372 
373 sal_Bool CommandLineArgs::InterpretCommandLineParameter( const ::rtl::OUString& aArg )
374 {
375     String aArgStr( aArg );
376 
377     if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-minimized" )) == sal_True )
378     {
379         SetBoolParam_Impl( CMD_BOOLPARAM_MINIMIZED, sal_True );
380         return sal_True;
381     }
382     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-invisible" )) == sal_True )
383     {
384         SetBoolParam_Impl( CMD_BOOLPARAM_INVISIBLE, sal_True );
385         return sal_True;
386     }
387     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-norestore" )) == sal_True )
388     {
389         SetBoolParam_Impl( CMD_BOOLPARAM_NORESTORE, sal_True );
390         return sal_True;
391     }
392     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nodefault" )) == sal_True )
393     {
394         SetBoolParam_Impl( CMD_BOOLPARAM_NODEFAULT, sal_True );
395         return sal_True;
396     }
397     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-bean" )) == sal_True )
398     {
399         SetBoolParam_Impl( CMD_BOOLPARAM_BEAN, sal_True );
400         return sal_True;
401     }
402     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-plugin" )) == sal_True )
403     {
404         SetBoolParam_Impl( CMD_BOOLPARAM_PLUGIN, sal_True );
405         return sal_True;
406     }
407     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-server" )) == sal_True )
408     {
409         SetBoolParam_Impl( CMD_BOOLPARAM_SERVER, sal_True );
410         return sal_True;
411     }
412     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-headless" )) == sal_True )
413     {
414         // Headless means also invisibile, so set this parameter to true!
415         SetBoolParam_Impl( CMD_BOOLPARAM_HEADLESS, sal_True );
416         SetBoolParam_Impl( CMD_BOOLPARAM_INVISIBLE, sal_True );
417         return sal_True;
418     }
419     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-quickstart" )) == sal_True )
420     {
421 #if defined(ENABLE_QUICKSTART_APPLET)
422         SetBoolParam_Impl( CMD_BOOLPARAM_QUICKSTART, sal_True );
423 #endif
424         SetBoolParam_Impl( CMD_BOOLPARAM_NOQUICKSTART, sal_False );
425         return sal_True;
426     }
427     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-quickstart=no" )))
428     {
429         SetBoolParam_Impl( CMD_BOOLPARAM_NOQUICKSTART, sal_True );
430         SetBoolParam_Impl( CMD_BOOLPARAM_QUICKSTART, sal_False );
431         return sal_True;
432     }
433     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-terminate_after_init" )) == sal_True )
434     {
435         SetBoolParam_Impl( CMD_BOOLPARAM_TERMINATEAFTERINIT, sal_True );
436         return sal_True;
437     }
438     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nofirststartwizard" )) == sal_True )
439     {
440         SetBoolParam_Impl( CMD_BOOLPARAM_NOFIRSTSTARTWIZARD, sal_True );
441         return sal_True;
442     }
443     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nologo" )) == sal_True )
444     {
445         SetBoolParam_Impl( CMD_BOOLPARAM_NOLOGO, sal_True );
446         return sal_True;
447     }
448     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nolockcheck" )) == sal_True )
449     {
450         SetBoolParam_Impl( CMD_BOOLPARAM_NOLOCKCHECK, sal_True );
451         // Workaround for automated testing
452         ::svt::DocumentLockFile::AllowInteraction( sal_False );
453 
454         return sal_True;
455     }
456     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-help" ))
457 	      || aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ))
458 	      || aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-?" )))
459     {
460         SetBoolParam_Impl( CMD_BOOLPARAM_HELP, sal_True );
461         return sal_True;
462     }
463     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpwriter" )) == sal_True )
464     {
465         SetBoolParam_Impl( CMD_BOOLPARAM_HELPWRITER, sal_True );
466         return sal_True;
467     }
468     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpcalc" )) == sal_True )
469     {
470         SetBoolParam_Impl( CMD_BOOLPARAM_HELPCALC, sal_True );
471         return sal_True;
472     }
473     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpdraw" )) == sal_True )
474     {
475         SetBoolParam_Impl( CMD_BOOLPARAM_HELPDRAW, sal_True );
476         return sal_True;
477     }
478     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpimpress" )) == sal_True )
479     {
480         SetBoolParam_Impl( CMD_BOOLPARAM_HELPIMPRESS, sal_True );
481         return sal_True;
482     }
483     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpbase" )) == sal_True )
484     {
485         SetBoolParam_Impl( CMD_BOOLPARAM_HELPBASE, sal_True );
486         return sal_True;
487     }
488     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpbasic" )) == sal_True )
489     {
490         SetBoolParam_Impl( CMD_BOOLPARAM_HELPBASIC, sal_True );
491         return sal_True;
492     }
493     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpmath" )) == sal_True )
494     {
495         SetBoolParam_Impl( CMD_BOOLPARAM_HELPMATH, sal_True );
496         return sal_True;
497     }
498 #ifdef MACOSX
499   /* #i84053# ignore -psn on Mac
500      Platform dependent #ifdef here is ugly, however this is currently
501      the only platform dependent parameter. Should more appear
502      we should find a better solution
503   */
504     else if ( aArg.compareToAscii( "-psn", 4 ) == 0 )
505     {
506         SetBoolParam_Impl( CMD_BOOLPARAM_PSN, sal_True );
507         return sal_True;
508     }
509 #endif
510     else if ( aArgStr.Copy(0, 8).EqualsIgnoreCaseAscii( "-accept=" ))
511     {
512         AddStringListParam_Impl( CMD_STRINGPARAM_ACCEPT, aArgStr.Copy( 8 ) );
513         return sal_True;
514     }
515     else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-unaccept=" ))
516     {
517         AddStringListParam_Impl( CMD_STRINGPARAM_UNACCEPT, aArgStr.Copy( 10 ) );
518         return sal_True;
519     }
520     else if ( aArgStr.CompareIgnoreCaseToAscii( "-portal," ,
521               RTL_CONSTASCII_LENGTH( "-portal," )) == COMPARE_EQUAL )
522     {
523         AddStringListParam_Impl( CMD_STRINGPARAM_PORTAL, aArgStr.Copy( RTL_CONSTASCII_LENGTH( "-portal," )) );
524         return sal_True;
525     }
526     else if ( aArgStr.Copy( 0, 7 ).EqualsIgnoreCaseAscii( "-userid" ))
527     {
528         if ( aArgStr.Len() > 8 )
529 	{
530 	    rtl::OUString aUserDir = aArgStr;
531 	    AddStringListParam_Impl( CMD_STRINGPARAM_USERDIR,
532 				     ::rtl::Uri::decode( aUserDir.copy( 8 ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ) );
533         }
534         return sal_True;
535     }
536     else if ( aArgStr.Copy( 0, 15).EqualsIgnoreCaseAscii( "-clientdisplay=" ))
537     {
538         AddStringListParam_Impl( CMD_STRINGPARAM_CLIENTDISPLAY, aArgStr.Copy( 15 ) );
539         return sal_True;
540     }
541     else if ( aArgStr.Copy(0, 9).EqualsIgnoreCaseAscii( "-version=" ))
542     {
543         AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 9 ) );
544         return sal_True;
545     }
546     else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-language=" ))
547     {
548         AddStringListParam_Impl( CMD_STRINGPARAM_LANGUAGE, aArgStr.Copy( 10 ) );
549         return sal_True;
550     }
551     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-writer" )) == sal_True )
552     {
553         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_WRITER );
554         if ( !bAlreadySet )
555 	    SetBoolParam_Impl( CMD_BOOLPARAM_WRITER, sal_True );
556         m_bDocumentArgs = true;
557         return sal_True;
558     }
559     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-calc" )) == sal_True )
560     {
561         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_CALC );
562         if ( !bAlreadySet )
563 	    SetBoolParam_Impl( CMD_BOOLPARAM_CALC, sal_True );
564         m_bDocumentArgs = true;
565         return sal_True;
566     }
567     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-draw" )) == sal_True )
568     {
569         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_DRAW );
570         if ( !bAlreadySet )
571 	    SetBoolParam_Impl( CMD_BOOLPARAM_DRAW, sal_True );
572         m_bDocumentArgs = true;
573         return sal_True;
574     }
575     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-impress" )) == sal_True )
576     {
577         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_IMPRESS );
578         if ( !bAlreadySet )
579 	    SetBoolParam_Impl( CMD_BOOLPARAM_IMPRESS, sal_True );
580         m_bDocumentArgs = true;
581         return sal_True;
582     }
583     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-base" )) == sal_True )
584     {
585         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_BASE );
586         if ( !bAlreadySet )
587 	    SetBoolParam_Impl( CMD_BOOLPARAM_BASE, sal_True );
588         m_bDocumentArgs = true;
589         return sal_True;
590     }
591     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-global" )) == sal_True )
592     {
593         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_GLOBAL );
594         if ( !bAlreadySet )
595 	    SetBoolParam_Impl( CMD_BOOLPARAM_GLOBAL, sal_True );
596         m_bDocumentArgs = true;
597         return sal_True;
598     }
599     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-math" )) == sal_True )
600     {
601         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_MATH );
602         if ( !bAlreadySet )
603 	    SetBoolParam_Impl( CMD_BOOLPARAM_MATH, sal_True );
604         m_bDocumentArgs = true;
605         return sal_True;
606     }
607     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-web" )) == sal_True )
608     {
609         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_WEB );
610         if ( !bAlreadySet )
611 	    SetBoolParam_Impl( CMD_BOOLPARAM_WEB, sal_True );
612         m_bDocumentArgs = true;
613         return sal_True;
614     }
615 
616     return sal_False;
617 }
618 
619 sal_Bool CommandLineArgs::CheckGroupMembers( GroupParamId nGroupId, BoolParam nExcludeMember ) const
620 {
621     // Check if at least one bool param out of a group is set. An exclude member can be provided.
622     for ( int i = 0; i < m_pGroupDefinitions[nGroupId].nCount; i++ )
623     {
624         BoolParam nParam = m_pGroupDefinitions[nGroupId].pGroupMembers[i];
625         if ( nParam != nExcludeMember && m_aBoolParams[nParam] )
626             return sal_True;
627     }
628 
629     return sal_False;
630 }
631 
632 void CommandLineArgs::ResetParamValues()
633 {
634     int i;
635     for ( i = 0; i < CMD_BOOLPARAM_COUNT; i++ )
636         m_aBoolParams[i] = sal_False;
637     for ( i = 0; i < CMD_STRINGPARAM_COUNT; i++ )
638         m_aStrSetParams[i] = sal_False;
639     m_eArgumentCount = NONE;
640     m_bDocumentArgs  = false;
641 }
642 
643 void CommandLineArgs::SetBoolParam( BoolParam eParam, sal_Bool bNewValue )
644 {
645 	osl::MutexGuard  aMutexGuard( m_aMutex );
646 
647 	OSL_ASSERT( ( eParam >= 0 && eParam < CMD_BOOLPARAM_COUNT ) );
648 	m_aBoolParams[eParam] = bNewValue;
649 }
650 
651 sal_Bool CommandLineArgs::IsMinimized() const
652 {
653 	osl::MutexGuard  aMutexGuard( m_aMutex );
654 	return m_aBoolParams[ CMD_BOOLPARAM_MINIMIZED ];
655 }
656 
657 sal_Bool CommandLineArgs::IsInvisible() const
658 {
659 	osl::MutexGuard  aMutexGuard( m_aMutex );
660 	return m_aBoolParams[ CMD_BOOLPARAM_INVISIBLE ];
661 }
662 
663 sal_Bool CommandLineArgs::IsNoRestore() const
664 {
665 	osl::MutexGuard  aMutexGuard( m_aMutex );
666 	return m_aBoolParams[ CMD_BOOLPARAM_NORESTORE ];
667 }
668 
669 sal_Bool CommandLineArgs::IsNoDefault() const
670 {
671 	osl::MutexGuard  aMutexGuard( m_aMutex );
672 	return m_aBoolParams[ CMD_BOOLPARAM_NODEFAULT ];
673 }
674 
675 sal_Bool CommandLineArgs::IsBean() const
676 {
677 	osl::MutexGuard  aMutexGuard( m_aMutex );
678 	return m_aBoolParams[ CMD_BOOLPARAM_BEAN ];
679 }
680 
681 sal_Bool CommandLineArgs::IsServer() const
682 {
683 	osl::MutexGuard  aMutexGuard( m_aMutex );
684 	return m_aBoolParams[ CMD_BOOLPARAM_SERVER ];
685 }
686 
687 sal_Bool CommandLineArgs::IsHeadless() const
688 {
689 	osl::MutexGuard  aMutexGuard( m_aMutex );
690 	return m_aBoolParams[ CMD_BOOLPARAM_HEADLESS ];
691 }
692 
693 sal_Bool CommandLineArgs::IsQuickstart() const
694 {
695 	osl::MutexGuard  aMutexGuard( m_aMutex );
696 	return m_aBoolParams[ CMD_BOOLPARAM_QUICKSTART ];
697 }
698 
699 sal_Bool CommandLineArgs::IsNoQuickstart() const
700 {
701     osl::MutexGuard aMutexGuard( m_aMutex );
702     return m_aBoolParams[ CMD_BOOLPARAM_NOQUICKSTART ];
703 }
704 
705 sal_Bool CommandLineArgs::IsTerminateAfterInit() const
706 {
707 	osl::MutexGuard  aMutexGuard( m_aMutex );
708 	return m_aBoolParams[ CMD_BOOLPARAM_TERMINATEAFTERINIT ];
709 }
710 
711 sal_Bool CommandLineArgs::IsNoFirstStartWizard() const
712 {
713 	osl::MutexGuard  aMutexGuard( m_aMutex );
714 	return m_aBoolParams[ CMD_BOOLPARAM_NOFIRSTSTARTWIZARD ];
715 }
716 
717 sal_Bool CommandLineArgs::IsNoLogo() const
718 {
719 	osl::MutexGuard  aMutexGuard( m_aMutex );
720 	return m_aBoolParams[ CMD_BOOLPARAM_NOLOGO ];
721 }
722 
723 sal_Bool CommandLineArgs::IsNoLockcheck() const
724 {
725 	osl::MutexGuard  aMutexGuard( m_aMutex );
726 	return m_aBoolParams[ CMD_BOOLPARAM_NOLOCKCHECK ];
727 }
728 
729 sal_Bool CommandLineArgs::IsHelp() const
730 {
731 	osl::MutexGuard  aMutexGuard( m_aMutex );
732 	return m_aBoolParams[ CMD_BOOLPARAM_HELP ];
733 }
734 sal_Bool CommandLineArgs::IsHelpWriter() const
735 {
736 	osl::MutexGuard  aMutexGuard( m_aMutex );
737 	return m_aBoolParams[ CMD_BOOLPARAM_HELPWRITER ];
738 }
739 
740 sal_Bool CommandLineArgs::IsHelpCalc() const
741 {
742 	osl::MutexGuard  aMutexGuard( m_aMutex );
743 	return m_aBoolParams[ CMD_BOOLPARAM_HELPCALC ];
744 }
745 
746 sal_Bool CommandLineArgs::IsHelpDraw() const
747 {
748 	osl::MutexGuard  aMutexGuard( m_aMutex );
749 	return m_aBoolParams[ CMD_BOOLPARAM_HELPDRAW ];
750 }
751 
752 sal_Bool CommandLineArgs::IsHelpImpress() const
753 {
754 	osl::MutexGuard  aMutexGuard( m_aMutex );
755 	return m_aBoolParams[ CMD_BOOLPARAM_HELPIMPRESS ];
756 }
757 
758 sal_Bool CommandLineArgs::IsHelpBase() const
759 {
760 	osl::MutexGuard  aMutexGuard( m_aMutex );
761 	return m_aBoolParams[ CMD_BOOLPARAM_HELPBASE ];
762 }
763 sal_Bool CommandLineArgs::IsHelpMath() const
764 {
765 	osl::MutexGuard  aMutexGuard( m_aMutex );
766 	return m_aBoolParams[ CMD_BOOLPARAM_HELPMATH ];
767 }
768 sal_Bool CommandLineArgs::IsHelpBasic() const
769 {
770 	osl::MutexGuard  aMutexGuard( m_aMutex );
771 	return m_aBoolParams[ CMD_BOOLPARAM_HELPBASIC ];
772 }
773 
774 sal_Bool CommandLineArgs::IsWriter() const
775 {
776 	osl::MutexGuard  aMutexGuard( m_aMutex );
777 	return m_aBoolParams[ CMD_BOOLPARAM_WRITER ];
778 }
779 
780 sal_Bool CommandLineArgs::IsCalc() const
781 {
782 	osl::MutexGuard  aMutexGuard( m_aMutex );
783 	return m_aBoolParams[ CMD_BOOLPARAM_CALC ];
784 }
785 
786 sal_Bool CommandLineArgs::IsDraw() const
787 {
788 	osl::MutexGuard  aMutexGuard( m_aMutex );
789 	return m_aBoolParams[ CMD_BOOLPARAM_DRAW ];
790 }
791 
792 sal_Bool CommandLineArgs::IsImpress() const
793 {
794 	osl::MutexGuard  aMutexGuard( m_aMutex );
795 	return m_aBoolParams[ CMD_BOOLPARAM_IMPRESS ];
796 }
797 
798 sal_Bool CommandLineArgs::IsBase() const
799 {
800 	osl::MutexGuard  aMutexGuard( m_aMutex );
801 	return m_aBoolParams[ CMD_BOOLPARAM_BASE ];
802 }
803 
804 sal_Bool CommandLineArgs::IsGlobal() const
805 {
806 	osl::MutexGuard  aMutexGuard( m_aMutex );
807 	return m_aBoolParams[ CMD_BOOLPARAM_GLOBAL ];
808 }
809 
810 sal_Bool CommandLineArgs::IsMath() const
811 {
812 	osl::MutexGuard  aMutexGuard( m_aMutex );
813 	return m_aBoolParams[ CMD_BOOLPARAM_MATH ];
814 }
815 
816 sal_Bool CommandLineArgs::IsWeb() const
817 {
818 	osl::MutexGuard  aMutexGuard( m_aMutex );
819 	return m_aBoolParams[ CMD_BOOLPARAM_WEB ];
820 }
821 
822 sal_Bool CommandLineArgs::HasModuleParam() const
823 {
824 	osl::MutexGuard  aMutexGuard( m_aMutex );
825 	return CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_COUNT );
826 }
827 
828 sal_Bool CommandLineArgs::GetPortalConnectString( ::rtl::OUString& rPara ) const
829 {
830 	osl::MutexGuard  aMutexGuard( m_aMutex );
831 	rPara = m_aStrParams[ CMD_STRINGPARAM_PORTAL ];
832 	return m_aStrSetParams[ CMD_STRINGPARAM_PORTAL ];
833 }
834 
835 sal_Bool CommandLineArgs::GetAcceptString( ::rtl::OUString& rPara ) const
836 {
837 	osl::MutexGuard  aMutexGuard( m_aMutex );
838 	rPara = m_aStrParams[ CMD_STRINGPARAM_ACCEPT ];
839 	return m_aStrSetParams[ CMD_STRINGPARAM_ACCEPT ];
840 }
841 
842 sal_Bool CommandLineArgs::GetUnAcceptString( ::rtl::OUString& rPara ) const
843 {
844 	osl::MutexGuard  aMutexGuard( m_aMutex );
845 	rPara = m_aStrParams[ CMD_STRINGPARAM_UNACCEPT ];
846 	return m_aStrSetParams[ CMD_STRINGPARAM_UNACCEPT ];
847 }
848 
849 sal_Bool CommandLineArgs::GetOpenList( ::rtl::OUString& rPara) const
850 {
851 	osl::MutexGuard  aMutexGuard( m_aMutex );
852 	rPara = m_aStrParams[ CMD_STRINGPARAM_OPENLIST ];
853 	return m_aStrSetParams[ CMD_STRINGPARAM_OPENLIST ];
854 }
855 
856 sal_Bool CommandLineArgs::GetViewList( ::rtl::OUString& rPara) const
857 {
858 	osl::MutexGuard  aMutexGuard( m_aMutex );
859 	rPara = m_aStrParams[ CMD_STRINGPARAM_VIEWLIST ];
860 	return m_aStrSetParams[ CMD_STRINGPARAM_VIEWLIST ];
861 }
862 
863 sal_Bool CommandLineArgs::GetStartList( ::rtl::OUString& rPara) const
864 {
865       osl::MutexGuard  aMutexGuard( m_aMutex );
866       rPara = m_aStrParams[ CMD_STRINGPARAM_STARTLIST ];
867       return m_aStrSetParams[ CMD_STRINGPARAM_STARTLIST ];
868 }
869 
870 sal_Bool CommandLineArgs::GetForceOpenList( ::rtl::OUString& rPara) const
871 {
872 	osl::MutexGuard  aMutexGuard( m_aMutex );
873 	rPara = m_aStrParams[ CMD_STRINGPARAM_FORCEOPENLIST ];
874 	return m_aStrSetParams[ CMD_STRINGPARAM_FORCEOPENLIST ];
875 }
876 
877 sal_Bool CommandLineArgs::GetForceNewList( ::rtl::OUString& rPara) const
878 {
879 	osl::MutexGuard  aMutexGuard( m_aMutex );
880 	rPara = m_aStrParams[ CMD_STRINGPARAM_FORCENEWLIST ];
881 	return m_aStrSetParams[ CMD_STRINGPARAM_FORCENEWLIST ];
882 }
883 
884 sal_Bool CommandLineArgs::GetPrintList( ::rtl::OUString& rPara) const
885 {
886 	osl::MutexGuard  aMutexGuard( m_aMutex );
887 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTLIST ];
888 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTLIST ];
889 }
890 
891 sal_Bool CommandLineArgs::GetPrintToList( ::rtl::OUString& rPara ) const
892 {
893 	osl::MutexGuard  aMutexGuard( m_aMutex );
894 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTTOLIST ];
895 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTTOLIST ];
896 }
897 
898 sal_Bool CommandLineArgs::GetPrinterName( ::rtl::OUString& rPara ) const
899 {
900 	osl::MutexGuard  aMutexGuard( m_aMutex );
901 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTERNAME ];
902 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTERNAME ];
903 }
904 
905 sal_Bool CommandLineArgs::GetLanguage( ::rtl::OUString& rPara ) const
906 {
907 	osl::MutexGuard  aMutexGuard( m_aMutex );
908 	rPara = m_aStrParams[ CMD_STRINGPARAM_LANGUAGE ];
909 	return m_aStrSetParams[ CMD_STRINGPARAM_LANGUAGE ];
910 }
911 
912 sal_Bool CommandLineArgs::IsEmpty() const
913 {
914     osl::MutexGuard  aMutexGuard( m_aMutex );
915     return m_eArgumentCount == NONE;
916 }
917 
918 sal_Bool CommandLineArgs::IsEmptyOrAcceptOnly() const
919 {
920     osl::MutexGuard  aMutexGuard( m_aMutex );
921 
922     return m_eArgumentCount == NONE ||
923            ( ( m_eArgumentCount == ONE ) && ( m_aStrParams[ CMD_STRINGPARAM_ACCEPT ].getLength() )) ||
924            ( ( m_eArgumentCount == ONE ) && m_aBoolParams[ CMD_BOOLPARAM_PSN ] );
925 }
926 
927 sal_Bool CommandLineArgs::WantsToLoadDocument() const
928 {
929     osl::MutexGuard  aMutexGuard( m_aMutex );
930     return m_bDocumentArgs;
931 }
932 
933 } // namespace desktop
934