xref: /trunk/main/desktop/source/app/cmdlineargs.cxx (revision 7f5c89d5)
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:
ExtCommandLineSupplier()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 
~ExtCommandLineSupplier()61     virtual ~ExtCommandLineSupplier() {}
62 
getCwdUrl()63     virtual boost::optional< rtl::OUString > getCwdUrl() { return m_cwdUrl; }
64 
next(rtl::OUString * argument)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 
Exception()100 CommandLineArgs::Supplier::Exception::Exception() {}
101 
Exception(Exception const &)102 CommandLineArgs::Supplier::Exception::Exception(Exception const &) {}
103 
~Exception()104 CommandLineArgs::Supplier::Exception::~Exception() {}
105 
106 CommandLineArgs::Supplier::Exception &
operator =(Exception const &)107 CommandLineArgs::Supplier::Exception::operator =(Exception const &)
108 { return *this; }
109 
~Supplier()110 CommandLineArgs::Supplier::~Supplier() {}
111 
112 // initialize class with command line parameters from process environment
CommandLineArgs()113 CommandLineArgs::CommandLineArgs()
114 {
115 	ResetParamValues();
116     ExtCommandLineSupplier s;
117 	ParseCommandLine_Impl( s );
118 }
119 
CommandLineArgs(Supplier & supplier)120 CommandLineArgs::CommandLineArgs( Supplier& supplier )
121 {
122 	ResetParamValues();
123 	ParseCommandLine_Impl( supplier );
124 }
125 
126 // ----------------------------------------------------------------------------
127 
ParseCommandLine_Impl(Supplier & supplier)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 
AddStringListParam_Impl(StringParam eParam,const rtl::OUString & aParam)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 
SetBoolParam_Impl(BoolParam eParam,sal_Bool bValue)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 
InterpretCommandLineParameter(const::rtl::OUString & aArg)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( "-conversionmode" )) == sal_True )
420     {
421         // ConversionMode means also headless and invisibile, so set these parameters to true!
422         SetBoolParam_Impl( CMD_BOOLPARAM_HEADLESS, sal_True );
423         SetBoolParam_Impl( CMD_BOOLPARAM_INVISIBLE, sal_True );
424         SetBoolParam_Impl( CMD_BOOLPARAM_CONVERSIONMODE, sal_True );
425         return sal_True;
426     }
427     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-quickstart" )) == sal_True )
428     {
429 #if defined(ENABLE_QUICKSTART_APPLET)
430         SetBoolParam_Impl( CMD_BOOLPARAM_QUICKSTART, sal_True );
431 #endif
432         SetBoolParam_Impl( CMD_BOOLPARAM_NOQUICKSTART, sal_False );
433         return sal_True;
434     }
435     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-quickstart=no" )))
436     {
437         SetBoolParam_Impl( CMD_BOOLPARAM_NOQUICKSTART, sal_True );
438         SetBoolParam_Impl( CMD_BOOLPARAM_QUICKSTART, sal_False );
439         return sal_True;
440     }
441     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-terminate_after_init" )) == sal_True )
442     {
443         SetBoolParam_Impl( CMD_BOOLPARAM_TERMINATEAFTERINIT, sal_True );
444         return sal_True;
445     }
446     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nofirststartwizard" )) == sal_True )
447     {
448         SetBoolParam_Impl( CMD_BOOLPARAM_NOFIRSTSTARTWIZARD, sal_True );
449         return sal_True;
450     }
451     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nologo" )) == sal_True )
452     {
453         SetBoolParam_Impl( CMD_BOOLPARAM_NOLOGO, sal_True );
454         return sal_True;
455     }
456     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-nolockcheck" )) == sal_True )
457     {
458         SetBoolParam_Impl( CMD_BOOLPARAM_NOLOCKCHECK, sal_True );
459         // Workaround for automated testing
460         ::svt::DocumentLockFile::AllowInteraction( sal_False );
461 
462         return sal_True;
463     }
464     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-help" ))
465 	      || aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-h" ))
466 	      || aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-?" )))
467     {
468         SetBoolParam_Impl( CMD_BOOLPARAM_HELP, sal_True );
469         return sal_True;
470     }
471     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpwriter" )) == sal_True )
472     {
473         SetBoolParam_Impl( CMD_BOOLPARAM_HELPWRITER, sal_True );
474         return sal_True;
475     }
476     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpcalc" )) == sal_True )
477     {
478         SetBoolParam_Impl( CMD_BOOLPARAM_HELPCALC, sal_True );
479         return sal_True;
480     }
481     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpdraw" )) == sal_True )
482     {
483         SetBoolParam_Impl( CMD_BOOLPARAM_HELPDRAW, sal_True );
484         return sal_True;
485     }
486     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpimpress" )) == sal_True )
487     {
488         SetBoolParam_Impl( CMD_BOOLPARAM_HELPIMPRESS, sal_True );
489         return sal_True;
490     }
491     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpbase" )) == sal_True )
492     {
493         SetBoolParam_Impl( CMD_BOOLPARAM_HELPBASE, sal_True );
494         return sal_True;
495     }
496     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpbasic" )) == sal_True )
497     {
498         SetBoolParam_Impl( CMD_BOOLPARAM_HELPBASIC, sal_True );
499         return sal_True;
500     }
501     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-helpmath" )) == sal_True )
502     {
503         SetBoolParam_Impl( CMD_BOOLPARAM_HELPMATH, sal_True );
504         return sal_True;
505     }
506 #ifdef MACOSX
507   /* #i84053# ignore -psn on Mac
508      Platform dependent #ifdef here is ugly, however this is currently
509      the only platform dependent parameter. Should more appear
510      we should find a better solution
511   */
512     else if ( aArg.compareToAscii( "-psn", 4 ) == 0 )
513     {
514         SetBoolParam_Impl( CMD_BOOLPARAM_PSN, sal_True );
515         return sal_True;
516     }
517 #endif
518     else if ( aArgStr.Copy(0, 8).EqualsIgnoreCaseAscii( "-accept=" ))
519     {
520         AddStringListParam_Impl( CMD_STRINGPARAM_ACCEPT, aArgStr.Copy( 8 ) );
521         return sal_True;
522     }
523     else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-unaccept=" ))
524     {
525         AddStringListParam_Impl( CMD_STRINGPARAM_UNACCEPT, aArgStr.Copy( 10 ) );
526         return sal_True;
527     }
528     else if ( aArgStr.CompareIgnoreCaseToAscii( "-portal," ,
529               RTL_CONSTASCII_LENGTH( "-portal," )) == COMPARE_EQUAL )
530     {
531         AddStringListParam_Impl( CMD_STRINGPARAM_PORTAL, aArgStr.Copy( RTL_CONSTASCII_LENGTH( "-portal," )) );
532         return sal_True;
533     }
534     else if ( aArgStr.Copy( 0, 7 ).EqualsIgnoreCaseAscii( "-userid" ))
535     {
536         if ( aArgStr.Len() > 8 )
537 	{
538 	    rtl::OUString aUserDir = aArgStr;
539 	    AddStringListParam_Impl( CMD_STRINGPARAM_USERDIR,
540 				     ::rtl::Uri::decode( aUserDir.copy( 8 ), rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 ) );
541         }
542         return sal_True;
543     }
544     else if ( aArgStr.Copy( 0, 15).EqualsIgnoreCaseAscii( "-clientdisplay=" ))
545     {
546         AddStringListParam_Impl( CMD_STRINGPARAM_CLIENTDISPLAY, aArgStr.Copy( 15 ) );
547         return sal_True;
548     }
549     else if ( aArgStr.Copy(0, 9).EqualsIgnoreCaseAscii( "-version=" ))
550     {
551         AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 9 ) );
552         return sal_True;
553     }
554     else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-language=" ))
555     {
556         AddStringListParam_Impl( CMD_STRINGPARAM_LANGUAGE, aArgStr.Copy( 10 ) );
557         return sal_True;
558     }
559     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-writer" )) == sal_True )
560     {
561         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_WRITER );
562         if ( !bAlreadySet )
563 	    SetBoolParam_Impl( CMD_BOOLPARAM_WRITER, sal_True );
564         m_bDocumentArgs = true;
565         return sal_True;
566     }
567     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-calc" )) == sal_True )
568     {
569         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_CALC );
570         if ( !bAlreadySet )
571 	    SetBoolParam_Impl( CMD_BOOLPARAM_CALC, sal_True );
572         m_bDocumentArgs = true;
573         return sal_True;
574     }
575     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-draw" )) == sal_True )
576     {
577         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_DRAW );
578         if ( !bAlreadySet )
579 	    SetBoolParam_Impl( CMD_BOOLPARAM_DRAW, sal_True );
580         m_bDocumentArgs = true;
581         return sal_True;
582     }
583     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-impress" )) == sal_True )
584     {
585         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_IMPRESS );
586         if ( !bAlreadySet )
587 	    SetBoolParam_Impl( CMD_BOOLPARAM_IMPRESS, sal_True );
588         m_bDocumentArgs = true;
589         return sal_True;
590     }
591     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-base" )) == sal_True )
592     {
593         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_BASE );
594         if ( !bAlreadySet )
595 	    SetBoolParam_Impl( CMD_BOOLPARAM_BASE, sal_True );
596         m_bDocumentArgs = true;
597         return sal_True;
598     }
599     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-global" )) == sal_True )
600     {
601         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_GLOBAL );
602         if ( !bAlreadySet )
603 	    SetBoolParam_Impl( CMD_BOOLPARAM_GLOBAL, sal_True );
604         m_bDocumentArgs = true;
605         return sal_True;
606     }
607     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-math" )) == sal_True )
608     {
609         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_MATH );
610         if ( !bAlreadySet )
611 	    SetBoolParam_Impl( CMD_BOOLPARAM_MATH, sal_True );
612         m_bDocumentArgs = true;
613         return sal_True;
614     }
615     else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-web" )) == sal_True )
616     {
617         sal_Bool bAlreadySet = CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_WEB );
618         if ( !bAlreadySet )
619 	    SetBoolParam_Impl( CMD_BOOLPARAM_WEB, sal_True );
620         m_bDocumentArgs = true;
621         return sal_True;
622     }
623 
624     return sal_False;
625 }
626 
CheckGroupMembers(GroupParamId nGroupId,BoolParam nExcludeMember) const627 sal_Bool CommandLineArgs::CheckGroupMembers( GroupParamId nGroupId, BoolParam nExcludeMember ) const
628 {
629     // Check if at least one bool param out of a group is set. An exclude member can be provided.
630     for ( int i = 0; i < m_pGroupDefinitions[nGroupId].nCount; i++ )
631     {
632         BoolParam nParam = m_pGroupDefinitions[nGroupId].pGroupMembers[i];
633         if ( nParam != nExcludeMember && m_aBoolParams[nParam] )
634             return sal_True;
635     }
636 
637     return sal_False;
638 }
639 
ResetParamValues()640 void CommandLineArgs::ResetParamValues()
641 {
642     int i;
643     for ( i = 0; i < CMD_BOOLPARAM_COUNT; i++ )
644         m_aBoolParams[i] = sal_False;
645     for ( i = 0; i < CMD_STRINGPARAM_COUNT; i++ )
646         m_aStrSetParams[i] = sal_False;
647     m_eArgumentCount = NONE;
648     m_bDocumentArgs  = false;
649 }
650 
SetBoolParam(BoolParam eParam,sal_Bool bNewValue)651 void CommandLineArgs::SetBoolParam( BoolParam eParam, sal_Bool bNewValue )
652 {
653 	osl::MutexGuard  aMutexGuard( m_aMutex );
654 
655 	OSL_ASSERT( ( eParam >= 0 && eParam < CMD_BOOLPARAM_COUNT ) );
656 	m_aBoolParams[eParam] = bNewValue;
657 }
658 
IsMinimized() const659 sal_Bool CommandLineArgs::IsMinimized() const
660 {
661 	osl::MutexGuard  aMutexGuard( m_aMutex );
662 	return m_aBoolParams[ CMD_BOOLPARAM_MINIMIZED ];
663 }
664 
IsInvisible() const665 sal_Bool CommandLineArgs::IsInvisible() const
666 {
667 	osl::MutexGuard  aMutexGuard( m_aMutex );
668 	return m_aBoolParams[ CMD_BOOLPARAM_INVISIBLE ];
669 }
670 
IsNoRestore() const671 sal_Bool CommandLineArgs::IsNoRestore() const
672 {
673 	osl::MutexGuard  aMutexGuard( m_aMutex );
674 	return m_aBoolParams[ CMD_BOOLPARAM_NORESTORE ];
675 }
676 
IsNoDefault() const677 sal_Bool CommandLineArgs::IsNoDefault() const
678 {
679 	osl::MutexGuard  aMutexGuard( m_aMutex );
680 	return m_aBoolParams[ CMD_BOOLPARAM_NODEFAULT ];
681 }
682 
IsBean() const683 sal_Bool CommandLineArgs::IsBean() const
684 {
685 	osl::MutexGuard  aMutexGuard( m_aMutex );
686 	return m_aBoolParams[ CMD_BOOLPARAM_BEAN ];
687 }
688 
IsServer() const689 sal_Bool CommandLineArgs::IsServer() const
690 {
691 	osl::MutexGuard  aMutexGuard( m_aMutex );
692 	return m_aBoolParams[ CMD_BOOLPARAM_SERVER ];
693 }
694 
IsHeadless() const695 sal_Bool CommandLineArgs::IsHeadless() const
696 {
697 	osl::MutexGuard  aMutexGuard( m_aMutex );
698 	return m_aBoolParams[ CMD_BOOLPARAM_HEADLESS ];
699 }
700 
IsConversionMode() const701 sal_Bool CommandLineArgs::IsConversionMode() const
702 {
703 	osl::MutexGuard  aMutexGuard( m_aMutex );
704 	return m_aBoolParams[ CMD_BOOLPARAM_CONVERSIONMODE ];
705 }
706 
IsQuickstart() const707 sal_Bool CommandLineArgs::IsQuickstart() const
708 {
709 	osl::MutexGuard  aMutexGuard( m_aMutex );
710 	return m_aBoolParams[ CMD_BOOLPARAM_QUICKSTART ];
711 }
712 
IsNoQuickstart() const713 sal_Bool CommandLineArgs::IsNoQuickstart() const
714 {
715     osl::MutexGuard aMutexGuard( m_aMutex );
716     return m_aBoolParams[ CMD_BOOLPARAM_NOQUICKSTART ];
717 }
718 
IsTerminateAfterInit() const719 sal_Bool CommandLineArgs::IsTerminateAfterInit() const
720 {
721 	osl::MutexGuard  aMutexGuard( m_aMutex );
722 	return m_aBoolParams[ CMD_BOOLPARAM_TERMINATEAFTERINIT ];
723 }
724 
IsNoFirstStartWizard() const725 sal_Bool CommandLineArgs::IsNoFirstStartWizard() const
726 {
727 	osl::MutexGuard  aMutexGuard( m_aMutex );
728 	return m_aBoolParams[ CMD_BOOLPARAM_NOFIRSTSTARTWIZARD ];
729 }
730 
IsNoLogo() const731 sal_Bool CommandLineArgs::IsNoLogo() const
732 {
733 	osl::MutexGuard  aMutexGuard( m_aMutex );
734 	return m_aBoolParams[ CMD_BOOLPARAM_NOLOGO ];
735 }
736 
IsNoLockcheck() const737 sal_Bool CommandLineArgs::IsNoLockcheck() const
738 {
739 	osl::MutexGuard  aMutexGuard( m_aMutex );
740 	return m_aBoolParams[ CMD_BOOLPARAM_NOLOCKCHECK ];
741 }
742 
IsHelp() const743 sal_Bool CommandLineArgs::IsHelp() const
744 {
745 	osl::MutexGuard  aMutexGuard( m_aMutex );
746 	return m_aBoolParams[ CMD_BOOLPARAM_HELP ];
747 }
IsHelpWriter() const748 sal_Bool CommandLineArgs::IsHelpWriter() const
749 {
750 	osl::MutexGuard  aMutexGuard( m_aMutex );
751 	return m_aBoolParams[ CMD_BOOLPARAM_HELPWRITER ];
752 }
753 
IsHelpCalc() const754 sal_Bool CommandLineArgs::IsHelpCalc() const
755 {
756 	osl::MutexGuard  aMutexGuard( m_aMutex );
757 	return m_aBoolParams[ CMD_BOOLPARAM_HELPCALC ];
758 }
759 
IsHelpDraw() const760 sal_Bool CommandLineArgs::IsHelpDraw() const
761 {
762 	osl::MutexGuard  aMutexGuard( m_aMutex );
763 	return m_aBoolParams[ CMD_BOOLPARAM_HELPDRAW ];
764 }
765 
IsHelpImpress() const766 sal_Bool CommandLineArgs::IsHelpImpress() const
767 {
768 	osl::MutexGuard  aMutexGuard( m_aMutex );
769 	return m_aBoolParams[ CMD_BOOLPARAM_HELPIMPRESS ];
770 }
771 
IsHelpBase() const772 sal_Bool CommandLineArgs::IsHelpBase() const
773 {
774 	osl::MutexGuard  aMutexGuard( m_aMutex );
775 	return m_aBoolParams[ CMD_BOOLPARAM_HELPBASE ];
776 }
IsHelpMath() const777 sal_Bool CommandLineArgs::IsHelpMath() const
778 {
779 	osl::MutexGuard  aMutexGuard( m_aMutex );
780 	return m_aBoolParams[ CMD_BOOLPARAM_HELPMATH ];
781 }
IsHelpBasic() const782 sal_Bool CommandLineArgs::IsHelpBasic() const
783 {
784 	osl::MutexGuard  aMutexGuard( m_aMutex );
785 	return m_aBoolParams[ CMD_BOOLPARAM_HELPBASIC ];
786 }
787 
IsWriter() const788 sal_Bool CommandLineArgs::IsWriter() const
789 {
790 	osl::MutexGuard  aMutexGuard( m_aMutex );
791 	return m_aBoolParams[ CMD_BOOLPARAM_WRITER ];
792 }
793 
IsCalc() const794 sal_Bool CommandLineArgs::IsCalc() const
795 {
796 	osl::MutexGuard  aMutexGuard( m_aMutex );
797 	return m_aBoolParams[ CMD_BOOLPARAM_CALC ];
798 }
799 
IsDraw() const800 sal_Bool CommandLineArgs::IsDraw() const
801 {
802 	osl::MutexGuard  aMutexGuard( m_aMutex );
803 	return m_aBoolParams[ CMD_BOOLPARAM_DRAW ];
804 }
805 
IsImpress() const806 sal_Bool CommandLineArgs::IsImpress() const
807 {
808 	osl::MutexGuard  aMutexGuard( m_aMutex );
809 	return m_aBoolParams[ CMD_BOOLPARAM_IMPRESS ];
810 }
811 
IsBase() const812 sal_Bool CommandLineArgs::IsBase() const
813 {
814 	osl::MutexGuard  aMutexGuard( m_aMutex );
815 	return m_aBoolParams[ CMD_BOOLPARAM_BASE ];
816 }
817 
IsGlobal() const818 sal_Bool CommandLineArgs::IsGlobal() const
819 {
820 	osl::MutexGuard  aMutexGuard( m_aMutex );
821 	return m_aBoolParams[ CMD_BOOLPARAM_GLOBAL ];
822 }
823 
IsMath() const824 sal_Bool CommandLineArgs::IsMath() const
825 {
826 	osl::MutexGuard  aMutexGuard( m_aMutex );
827 	return m_aBoolParams[ CMD_BOOLPARAM_MATH ];
828 }
829 
IsWeb() const830 sal_Bool CommandLineArgs::IsWeb() const
831 {
832 	osl::MutexGuard  aMutexGuard( m_aMutex );
833 	return m_aBoolParams[ CMD_BOOLPARAM_WEB ];
834 }
835 
HasModuleParam() const836 sal_Bool CommandLineArgs::HasModuleParam() const
837 {
838 	osl::MutexGuard  aMutexGuard( m_aMutex );
839 	return CheckGroupMembers( CMD_GRPID_MODULE, CMD_BOOLPARAM_COUNT );
840 }
841 
GetPortalConnectString(::rtl::OUString & rPara) const842 sal_Bool CommandLineArgs::GetPortalConnectString( ::rtl::OUString& rPara ) const
843 {
844 	osl::MutexGuard  aMutexGuard( m_aMutex );
845 	rPara = m_aStrParams[ CMD_STRINGPARAM_PORTAL ];
846 	return m_aStrSetParams[ CMD_STRINGPARAM_PORTAL ];
847 }
848 
GetAcceptString(::rtl::OUString & rPara) const849 sal_Bool CommandLineArgs::GetAcceptString( ::rtl::OUString& rPara ) const
850 {
851 	osl::MutexGuard  aMutexGuard( m_aMutex );
852 	rPara = m_aStrParams[ CMD_STRINGPARAM_ACCEPT ];
853 	return m_aStrSetParams[ CMD_STRINGPARAM_ACCEPT ];
854 }
855 
GetUnAcceptString(::rtl::OUString & rPara) const856 sal_Bool CommandLineArgs::GetUnAcceptString( ::rtl::OUString& rPara ) const
857 {
858 	osl::MutexGuard  aMutexGuard( m_aMutex );
859 	rPara = m_aStrParams[ CMD_STRINGPARAM_UNACCEPT ];
860 	return m_aStrSetParams[ CMD_STRINGPARAM_UNACCEPT ];
861 }
862 
GetOpenList(::rtl::OUString & rPara) const863 sal_Bool CommandLineArgs::GetOpenList( ::rtl::OUString& rPara) const
864 {
865 	osl::MutexGuard  aMutexGuard( m_aMutex );
866 	rPara = m_aStrParams[ CMD_STRINGPARAM_OPENLIST ];
867 	return m_aStrSetParams[ CMD_STRINGPARAM_OPENLIST ];
868 }
869 
GetViewList(::rtl::OUString & rPara) const870 sal_Bool CommandLineArgs::GetViewList( ::rtl::OUString& rPara) const
871 {
872 	osl::MutexGuard  aMutexGuard( m_aMutex );
873 	rPara = m_aStrParams[ CMD_STRINGPARAM_VIEWLIST ];
874 	return m_aStrSetParams[ CMD_STRINGPARAM_VIEWLIST ];
875 }
876 
GetStartList(::rtl::OUString & rPara) const877 sal_Bool CommandLineArgs::GetStartList( ::rtl::OUString& rPara) const
878 {
879       osl::MutexGuard  aMutexGuard( m_aMutex );
880       rPara = m_aStrParams[ CMD_STRINGPARAM_STARTLIST ];
881       return m_aStrSetParams[ CMD_STRINGPARAM_STARTLIST ];
882 }
883 
GetForceOpenList(::rtl::OUString & rPara) const884 sal_Bool CommandLineArgs::GetForceOpenList( ::rtl::OUString& rPara) const
885 {
886 	osl::MutexGuard  aMutexGuard( m_aMutex );
887 	rPara = m_aStrParams[ CMD_STRINGPARAM_FORCEOPENLIST ];
888 	return m_aStrSetParams[ CMD_STRINGPARAM_FORCEOPENLIST ];
889 }
890 
GetForceNewList(::rtl::OUString & rPara) const891 sal_Bool CommandLineArgs::GetForceNewList( ::rtl::OUString& rPara) const
892 {
893 	osl::MutexGuard  aMutexGuard( m_aMutex );
894 	rPara = m_aStrParams[ CMD_STRINGPARAM_FORCENEWLIST ];
895 	return m_aStrSetParams[ CMD_STRINGPARAM_FORCENEWLIST ];
896 }
897 
GetPrintList(::rtl::OUString & rPara) const898 sal_Bool CommandLineArgs::GetPrintList( ::rtl::OUString& rPara) const
899 {
900 	osl::MutexGuard  aMutexGuard( m_aMutex );
901 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTLIST ];
902 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTLIST ];
903 }
904 
GetPrintToList(::rtl::OUString & rPara) const905 sal_Bool CommandLineArgs::GetPrintToList( ::rtl::OUString& rPara ) const
906 {
907 	osl::MutexGuard  aMutexGuard( m_aMutex );
908 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTTOLIST ];
909 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTTOLIST ];
910 }
911 
GetPrinterName(::rtl::OUString & rPara) const912 sal_Bool CommandLineArgs::GetPrinterName( ::rtl::OUString& rPara ) const
913 {
914 	osl::MutexGuard  aMutexGuard( m_aMutex );
915 	rPara = m_aStrParams[ CMD_STRINGPARAM_PRINTERNAME ];
916 	return m_aStrSetParams[ CMD_STRINGPARAM_PRINTERNAME ];
917 }
918 
GetLanguage(::rtl::OUString & rPara) const919 sal_Bool CommandLineArgs::GetLanguage( ::rtl::OUString& rPara ) const
920 {
921 	osl::MutexGuard  aMutexGuard( m_aMutex );
922 	rPara = m_aStrParams[ CMD_STRINGPARAM_LANGUAGE ];
923 	return m_aStrSetParams[ CMD_STRINGPARAM_LANGUAGE ];
924 }
925 
IsEmpty() const926 sal_Bool CommandLineArgs::IsEmpty() const
927 {
928     osl::MutexGuard  aMutexGuard( m_aMutex );
929     return m_eArgumentCount == NONE;
930 }
931 
IsEmptyOrAcceptOnly() const932 sal_Bool CommandLineArgs::IsEmptyOrAcceptOnly() const
933 {
934     osl::MutexGuard  aMutexGuard( m_aMutex );
935 
936     return m_eArgumentCount == NONE ||
937            ( ( m_eArgumentCount == ONE ) && ( m_aStrParams[ CMD_STRINGPARAM_ACCEPT ].getLength() )) ||
938            ( ( m_eArgumentCount == ONE ) && m_aBoolParams[ CMD_BOOLPARAM_PSN ] );
939 }
940 
WantsToLoadDocument() const941 sal_Bool CommandLineArgs::WantsToLoadDocument() const
942 {
943     osl::MutexGuard  aMutexGuard( m_aMutex );
944     return m_bDocumentArgs;
945 }
946 
947 } // namespace desktop
948