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