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 31 #include <cstdlib> 32 #include <vector> 33 34 #include <memory> 35 #include <unistd.h> 36 #include "app.hxx" 37 #include "desktop.hrc" 38 #include "appinit.hxx" 39 #include "officeipcthread.hxx" 40 #include "cmdlineargs.hxx" 41 #include "desktopresid.hxx" 42 #include "dispatchwatcher.hxx" 43 #include "configinit.hxx" 44 #include "lockfile.hxx" 45 #include "checkinstall.hxx" 46 #include "cmdlinehelp.hxx" 47 #include "userinstall.hxx" 48 #include "desktopcontext.hxx" 49 #include "exithelper.hxx" 50 #include "../migration/pages.hxx" 51 52 #include <svtools/javacontext.hxx> 53 #include <com/sun/star/frame/XSessionManagerListener.hpp> 54 #include <com/sun/star/frame/XSynchronousDispatch.hpp> 55 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp> 56 #include <com/sun/star/configuration/CorruptedConfigurationException.hpp> 57 #include <com/sun/star/frame/XStorable.hpp> 58 #include <com/sun/star/util/XModifiable.hpp> 59 #include <com/sun/star/util/XFlushable.hpp> 60 #include <com/sun/star/system/XSystemShellExecute.hpp> 61 #include <com/sun/star/system/SystemShellExecuteFlags.hpp> 62 #include <com/sun/star/beans/XPropertySet.hpp> 63 #include <com/sun/star/lang/XComponent.hpp> 64 #include <com/sun/star/uno/RuntimeException.hpp> 65 #include <com/sun/star/io/IOException.hpp> 66 #include <com/sun/star/lang/IllegalArgumentException.hpp> 67 #include <com/sun/star/lang/WrappedTargetException.hpp> 68 #include <com/sun/star/frame/XDesktop.hpp> 69 #include <com/sun/star/frame/XComponentLoader.hpp> 70 #include <com/sun/star/view/XPrintable.hpp> 71 #include <com/sun/star/lang/XInitialization.hpp> 72 #include <com/sun/star/frame/XFramesSupplier.hpp> 73 #include <com/sun/star/awt/XTopWindow.hpp> 74 #include <com/sun/star/util/XURLTransformer.hpp> 75 #include <com/sun/star/util/URL.hpp> 76 #include <com/sun/star/util/XCloseable.hpp> 77 #include <com/sun/star/frame/XDispatch.hpp> 78 #include <com/sun/star/frame/XDispatchProvider.hpp> 79 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp> 80 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 81 #include <com/sun/star/configuration/MissingBootstrapFileException.hpp> 82 #include <com/sun/star/configuration/InvalidBootstrapFileException.hpp> 83 #include <com/sun/star/configuration/InstallationIncompleteException.hpp> 84 #include <com/sun/star/configuration/backend/BackendSetupException.hpp> 85 #include <com/sun/star/configuration/backend/BackendAccessException.hpp> 86 #include <com/sun/star/container/XEnumeration.hpp> 87 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 88 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 89 #include <com/sun/star/task/XJobExecutor.hpp> 90 #include <com/sun/star/task/XRestartManager.hpp> 91 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_ 92 #include <com/sun/star/task/XJob.hpp> 93 #endif 94 #include <com/sun/star/beans/XPropertySet.hpp> 95 #include <com/sun/star/beans/NamedValue.hpp> 96 #include <com/sun/star/task/XJob.hpp> 97 #include <com/sun/star/document/XEventListener.hpp> 98 #include <com/sun/star/ui/XUIElementFactoryRegistration.hpp> 99 #include <com/sun/star/frame/XUIControllerRegistration.hpp> 100 101 #include <com/sun/star/java/XJavaVM.hpp> 102 #include <tools/testtoolloader.hxx> 103 #include <tools/solar.h> 104 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 105 #include <toolkit/unohlp.hxx> 106 #endif 107 #include <vos/security.hxx> 108 #include <vos/ref.hxx> 109 #include <comphelper/processfactory.hxx> 110 #include <comphelper/componentcontext.hxx> 111 #include <comphelper/configurationhelper.hxx> 112 #ifndef _UTL__HXX_ 113 #include <unotools/configmgr.hxx> 114 #endif 115 #include <unotools/configitem.hxx> 116 #include <unotools/confignode.hxx> 117 #include <unotools/ucbhelper.hxx> 118 #include <tools/tempfile.hxx> 119 #include <tools/urlobj.hxx> 120 #include <unotools/moduleoptions.hxx> 121 #include <osl/module.h> 122 #include <osl/file.hxx> 123 #include <osl/signal.h> 124 #include <osl/thread.hxx> 125 #include <rtl/uuid.h> 126 #include <rtl/uri.hxx> 127 #include <unotools/pathoptions.hxx> 128 #include <svl/languageoptions.hxx> 129 #include <unotools/internaloptions.hxx> 130 #include <svtools/miscopt.hxx> 131 #include <svtools/menuoptions.hxx> 132 #include <unotools/syslocaleoptions.hxx> 133 #include <unotools/syslocale.hxx> 134 #include <svl/folderrestriction.hxx> 135 #include <svl/eitem.hxx> 136 #include <svl/itemset.hxx> 137 #include <unotools/tempfile.hxx> 138 #include <rtl/logfile.hxx> 139 #include <rtl/ustrbuf.hxx> 140 #include <rtl/strbuf.hxx> 141 #include <rtl/bootstrap.hxx> 142 #include <rtl/instance.hxx> 143 #include <unotools/configmgr.hxx> 144 #include <vcl/help.hxx> 145 #include <vcl/msgbox.hxx> 146 #include <vcl/bitmap.hxx> 147 #include <vcl/stdtext.hxx> 148 #include <vcl/msgbox.hxx> 149 #include <sfx2/sfx.hrc> 150 #include <sfx2/app.hxx> 151 #include <ucbhelper/contentbroker.hxx> 152 #include <unotools/bootstrap.hxx> 153 #include <cppuhelper/bootstrap.hxx> 154 155 #include "vos/process.hxx" 156 157 #include <svtools/fontsubstconfig.hxx> 158 #include <svtools/accessibilityoptions.hxx> 159 #include <svtools/apearcfg.hxx> 160 #include <unotools/misccfg.hxx> 161 #include <svtools/filter.hxx> 162 #include <unotools/regoptions.hxx> 163 164 #include "langselect.hxx" 165 166 #if defined MACOSX 167 #include <errno.h> 168 #include <sys/wait.h> 169 #endif 170 171 #define DEFINE_CONST_UNICODE(CONSTASCII) UniString(RTL_CONSTASCII_USTRINGPARAM(CONSTASCII)) 172 #define U2S(STRING) ::rtl::OUStringToOString(STRING, RTL_TEXTENCODING_UTF8) 173 174 using namespace vos; 175 using namespace rtl; 176 177 //Gives an ICE with MSVC6 178 //namespace css = ::com::sun::star; 179 180 using namespace ::com::sun::star::uno; 181 using namespace ::com::sun::star::util; 182 using namespace ::com::sun::star::lang; 183 using namespace ::com::sun::star::beans; 184 //using namespace ::com::sun::star::bridge; 185 using namespace ::com::sun::star::frame; 186 using namespace ::com::sun::star::document; 187 using namespace ::com::sun::star::view; 188 using namespace ::com::sun::star::task; 189 using namespace ::com::sun::star::system; 190 using namespace ::com::sun::star::ui::dialogs; 191 using namespace ::com::sun::star::container; 192 193 namespace css = ::com::sun::star; 194 195 ResMgr* desktop::Desktop::pResMgr = 0; 196 197 namespace desktop 198 { 199 200 static SalMainPipeExchangeSignalHandler* pSignalHandler = 0; 201 static sal_Bool _bCrashReporterEnabled = sal_True; 202 203 static const ::rtl::OUString CFG_PACKAGE_COMMON_HELP ( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.Office.Common/Help")); 204 static const ::rtl::OUString CFG_PATH_REG ( RTL_CONSTASCII_USTRINGPARAM( "Registration" )); 205 static const ::rtl::OUString CFG_ENTRY_REGURL ( RTL_CONSTASCII_USTRINGPARAM( "URL" )); 206 static const ::rtl::OUString CFG_ENTRY_TEMPLATEREGURL ( RTL_CONSTASCII_USTRINGPARAM( "TemplateURL" )); 207 208 static ::rtl::OUString getBrandSharePreregBundledPathURL(); 209 // ---------------------------------------------------------------------------- 210 211 ResMgr* Desktop::GetDesktopResManager() 212 { 213 if ( !Desktop::pResMgr ) 214 { 215 String aMgrName = String::CreateFromAscii( "dkt" ); 216 217 // Create desktop resource manager and bootstrap process 218 // was successful. Use default way to get language specific message. 219 if ( Application::IsInExecute() ) 220 Desktop::pResMgr = ResMgr::CreateResMgr( U2S( aMgrName )); 221 222 if ( !Desktop::pResMgr ) 223 { 224 // Use VCL to get the correct language specific message as we 225 // are in the bootstrap process and not able to get the installed 226 // language!! 227 /* 228 LanguageType aLanguageType = LANGUAGE_DONTKNOW; 229 230 Desktop::pResMgr = ResMgr::SearchCreateResMgr( U2S( aMgrName ), aLanguageType ); 231 AllSettings as = GetSettings(); 232 as.SetUILanguage(aLanguageType); 233 SetSettings(as); 234 */ 235 // LanguageSelection langselect; 236 OUString aUILocaleString = LanguageSelection::getLanguageString(); 237 sal_Int32 nIndex = 0; 238 OUString aLanguage = aUILocaleString.getToken( 0, '-', nIndex); 239 OUString aCountry = aUILocaleString.getToken( 0, '-', nIndex); 240 OUString aVariant = aUILocaleString.getToken( 0, '-', nIndex); 241 242 ::com::sun::star::lang::Locale aLocale( aLanguage, aCountry, aVariant ); 243 244 Desktop::pResMgr = ResMgr::SearchCreateResMgr( U2S( aMgrName ), aLocale); 245 AllSettings as = GetSettings(); 246 as.SetUILocale(aLocale); 247 SetSettings(as); 248 } 249 } 250 251 return Desktop::pResMgr; 252 } 253 254 // ---------------------------------------------------------------------------- 255 // Get a message string securely. There is a fallback string if the resource 256 // is not available. 257 258 OUString Desktop::GetMsgString( sal_uInt16 nId, const OUString& aFaultBackMsg ) 259 { 260 ResMgr* resMgr = GetDesktopResManager(); 261 if ( !resMgr ) 262 return aFaultBackMsg; 263 else 264 return OUString( String( ResId( nId, *resMgr ))); 265 } 266 267 OUString MakeStartupErrorMessage(OUString const & aErrorMessage) 268 { 269 OUStringBuffer aDiagnosticMessage( 100 ); 270 271 ResMgr* pResMgr = Desktop::GetDesktopResManager(); 272 if ( pResMgr ) 273 aDiagnosticMessage.append( OUString(String(ResId(STR_BOOTSTRAP_ERR_CANNOT_START, *pResMgr))) ); 274 else 275 aDiagnosticMessage.appendAscii( "The program cannot be started." ); 276 277 aDiagnosticMessage.appendAscii( "\n" ); 278 279 aDiagnosticMessage.append( aErrorMessage ); 280 281 return aDiagnosticMessage.makeStringAndClear(); 282 } 283 284 OUString MakeStartupConfigAccessErrorMessage( OUString const & aInternalErrMsg ) 285 { 286 OUStringBuffer aDiagnosticMessage( 200 ); 287 288 ResMgr* pResMgr = Desktop::GetDesktopResManager(); 289 if ( pResMgr ) 290 aDiagnosticMessage.append( OUString(String(ResId(STR_BOOTSTRAP_ERR_CFG_DATAACCESS, *pResMgr ))) ); 291 else 292 aDiagnosticMessage.appendAscii( "The program cannot be started." ); 293 294 if ( aInternalErrMsg.getLength() > 0 ) 295 { 296 aDiagnosticMessage.appendAscii( "\n\n" ); 297 if ( pResMgr ) 298 aDiagnosticMessage.append( OUString(String(ResId(STR_INTERNAL_ERRMSG, *pResMgr ))) ); 299 else 300 aDiagnosticMessage.appendAscii( "The following internal error has occured:\n\n" ); 301 aDiagnosticMessage.append( aInternalErrMsg ); 302 } 303 304 return aDiagnosticMessage.makeStringAndClear(); 305 } 306 307 //============================================================================= 308 // shows a simple error box with the given message ... but exits from these process ! 309 // 310 // Fatal errors cant be solved by the process ... nor any recovery can help. 311 // Mostly the installation was damaged and must be repaired manually .. or by calling 312 // setup again. 313 // 314 // On the other side we must make sure that no further actions will be possible within 315 // the current office process ! No pipe requests, no menu/toolbar/shortuct actions 316 // are allowed. Otherwise we will force a "crash inside a crash". 317 // 318 // Thats why we have to use a special native message box here which does not use yield :-) 319 //============================================================================= 320 void FatalError(const ::rtl::OUString& sMessage) 321 { 322 ::rtl::OUString sProductKey = ::utl::Bootstrap::getProductKey(); 323 if ( ! sProductKey.getLength()) 324 { 325 ::vos::OStartupInfo aInfo; 326 aInfo.getExecutableFile( sProductKey ); 327 328 ::sal_uInt32 nLastIndex = sProductKey.lastIndexOf('/'); 329 if ( nLastIndex > 0 ) 330 sProductKey = sProductKey.copy( nLastIndex+1 ); 331 } 332 333 ::rtl::OUStringBuffer sTitle (128); 334 sTitle.append (sProductKey ); 335 sTitle.appendAscii (" - Fatal Error"); 336 337 Application::ShowNativeErrorBox (sTitle.makeStringAndClear (), sMessage); 338 _exit(ExitHelper::E_FATAL_ERROR); 339 } 340 341 static bool ShouldSuppressUI(CommandLineArgs* pCmdLine) 342 { 343 return pCmdLine->IsInvisible() || 344 pCmdLine->IsHeadless() || 345 pCmdLine->IsQuickstart(); 346 } 347 348 CommandLineArgs* Desktop::GetCommandLineArgs() 349 { 350 static CommandLineArgs* pArgs = 0; 351 if ( !pArgs ) 352 { 353 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 354 if ( !pArgs ) 355 pArgs = new CommandLineArgs; 356 } 357 358 return pArgs; 359 } 360 361 sal_Bool InitConfiguration() 362 { 363 RTL_LOGFILE_CONTEXT( aLog, "desktop (jb99855) ::InitConfiguration" ); 364 365 Reference< XMultiServiceFactory > xProvider( CreateApplicationConfigurationProvider( ) ); 366 return xProvider.is(); 367 } 368 369 namespace 370 { 371 struct BrandName 372 : public rtl::Static< String, BrandName > {}; 373 struct Version 374 : public rtl::Static< String, Version > {}; 375 struct AboutBoxVersion 376 : public rtl::Static< String, AboutBoxVersion > {}; 377 struct OOOVendor 378 : public rtl::Static< String, OOOVendor > {}; 379 struct Extension 380 : public rtl::Static< String, Extension > {}; 381 struct XMLFileFormatName 382 : public rtl::Static< String, XMLFileFormatName > {}; 383 struct XMLFileFormatVersion 384 : public rtl::Static< String, XMLFileFormatVersion > {}; 385 struct WriterCompatibilityVersionOOo11 386 : public rtl::Static< String, WriterCompatibilityVersionOOo11 > {}; 387 } 388 389 void ReplaceStringHookProc( UniString& rStr ) 390 { 391 static int nAll = 0, nPro = 0; 392 393 nAll++; 394 if ( rStr.SearchAscii( "%PRODUCT" ) != STRING_NOTFOUND ) 395 { 396 String &rBrandName = BrandName::get(); 397 String &rVersion = Version::get(); 398 String &rAboutBoxVersion = AboutBoxVersion::get(); 399 String &rExtension = Extension::get(); 400 String &rXMLFileFormatName = XMLFileFormatName::get(); 401 String &rXMLFileFormatVersion = XMLFileFormatVersion::get(); 402 403 if ( !rBrandName.Len() ) 404 { 405 rtl::OUString aTmp; 406 Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ); 407 aRet >>= aTmp; 408 rBrandName = aTmp; 409 410 aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTXMLFILEFORMATNAME ); 411 aRet >>= aTmp; 412 rXMLFileFormatName = aTmp; 413 414 aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTXMLFILEFORMATVERSION ); 415 aRet >>= aTmp; 416 rXMLFileFormatVersion = aTmp; 417 418 aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTVERSION ); 419 aRet >>= aTmp; 420 rVersion = aTmp; 421 422 aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::ABOUTBOXPRODUCTVERSION ); 423 aRet >>= aTmp; 424 rAboutBoxVersion = aTmp; 425 426 if ( !rExtension.Len() ) 427 { 428 aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTEXTENSION ); 429 aRet >>= aTmp; 430 rExtension = aTmp; 431 } 432 } 433 434 nPro++; 435 rStr.SearchAndReplaceAllAscii( "%PRODUCTNAME", rBrandName ); 436 rStr.SearchAndReplaceAllAscii( "%PRODUCTVERSION", rVersion ); 437 rStr.SearchAndReplaceAllAscii( "%ABOUTBOXPRODUCTVERSION", rAboutBoxVersion ); 438 rStr.SearchAndReplaceAllAscii( "%PRODUCTEXTENSION", rExtension ); 439 rStr.SearchAndReplaceAllAscii( "%PRODUCTXMLFILEFORMATNAME", rXMLFileFormatName ); 440 rStr.SearchAndReplaceAllAscii( "%PRODUCTXMLFILEFORMATVERSION", rXMLFileFormatVersion ); 441 } 442 if ( rStr.SearchAscii( "%OOOVENDOR" ) != STRING_NOTFOUND ) 443 { 444 String &rOOOVendor = OOOVendor::get(); 445 446 if ( !rOOOVendor.Len() ) 447 { 448 rtl::OUString aTmp; 449 Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( 450 ::utl::ConfigManager::OOOVENDOR ); 451 aRet >>= aTmp; 452 rOOOVendor = aTmp; 453 454 } 455 rStr.SearchAndReplaceAllAscii( "%OOOVENDOR" ,rOOOVendor ); 456 } 457 458 if ( rStr.SearchAscii( "%WRITERCOMPATIBILITYVERSIONOOO11" ) != STRING_NOTFOUND ) 459 { 460 String &rWriterCompatibilityVersionOOo11 = WriterCompatibilityVersionOOo11::get(); 461 if ( !rWriterCompatibilityVersionOOo11.Len() ) 462 { 463 rtl::OUString aTmp; 464 Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( 465 ::utl::ConfigManager::WRITERCOMPATIBILITYVERSIONOOO11 ); 466 aRet >>= aTmp; 467 rWriterCompatibilityVersionOOo11 = aTmp; 468 } 469 470 rStr.SearchAndReplaceAllAscii( "%WRITERCOMPATIBILITYVERSIONOOO11", 471 rWriterCompatibilityVersionOOo11 ); 472 } 473 } 474 475 static const char pLastSyncFileName[] = "lastsynchronized"; 476 static const sal_Int32 nStrLenLastSync = 16; 477 478 static bool needsSynchronization( 479 ::rtl::OUString const & baseSynchronizedURL, ::rtl::OUString const & userSynchronizedURL ) 480 { 481 bool bNeedsSync( false ); 482 483 ::osl::DirectoryItem itemUserFile; 484 ::osl::File::RC err1 = 485 ::osl::DirectoryItem::get(userSynchronizedURL, itemUserFile); 486 487 //If it does not exist, then there is nothing to be done 488 if (err1 == ::osl::File::E_NOENT) 489 { 490 return true; 491 } 492 else if (err1 != ::osl::File::E_None) 493 { 494 OSL_ENSURE(0, "Cannot access lastsynchronized in user layer"); 495 return true; //sync just in case 496 } 497 498 //If last synchronized does not exist in base layer, then do nothing 499 ::osl::DirectoryItem itemBaseFile; 500 ::osl::File::RC err2 = ::osl::DirectoryItem::get(baseSynchronizedURL, itemBaseFile); 501 if (err2 == ::osl::File::E_NOENT) 502 { 503 return true; 504 505 } 506 else if (err2 != ::osl::File::E_None) 507 { 508 OSL_ENSURE(0, "Cannot access file lastsynchronized in base layer"); 509 return true; //sync just in case 510 } 511 512 //compare the modification time of the extension folder and the last 513 //modified file 514 ::osl::FileStatus statUser(FileStatusMask_ModifyTime); 515 ::osl::FileStatus statBase(FileStatusMask_ModifyTime); 516 if (itemUserFile.getFileStatus(statUser) == ::osl::File::E_None) 517 { 518 if (itemBaseFile.getFileStatus(statBase) == ::osl::File::E_None) 519 { 520 TimeValue timeUser = statUser.getModifyTime(); 521 TimeValue timeBase = statBase.getModifyTime(); 522 523 if (timeUser.Seconds < timeBase.Seconds) 524 bNeedsSync = true; 525 } 526 else 527 { 528 OSL_ASSERT(0); 529 bNeedsSync = true; 530 } 531 } 532 else 533 { 534 OSL_ASSERT(0); 535 bNeedsSync = true; 536 } 537 538 return bNeedsSync; 539 } 540 541 static ::rtl::OUString getBrandSharePreregBundledPathURL() 542 { 543 ::rtl::OUString url( 544 RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR/share/prereg/bundled")); 545 546 ::rtl::Bootstrap::expandMacros(url); 547 return url; 548 } 549 550 static ::rtl::OUString getUserBundledExtPathURL() 551 { 552 ::rtl::OUString folder( RTL_CONSTASCII_USTRINGPARAM( "$BUNDLED_EXTENSIONS_USER" )); 553 ::rtl::Bootstrap::expandMacros(folder); 554 555 return folder; 556 } 557 558 static ::rtl::OUString getLastSyncFileURLFromBrandInstallation() 559 { 560 ::rtl::OUString aURL = getBrandSharePreregBundledPathURL(); 561 ::sal_Int32 nLastIndex = aURL.lastIndexOf('/'); 562 563 ::rtl::OUStringBuffer aTmp( aURL ); 564 565 if ( nLastIndex != aURL.getLength()-1 ) 566 aTmp.appendAscii( "/" ); 567 aTmp.appendAscii( pLastSyncFileName ); 568 569 return aTmp.makeStringAndClear(); 570 } 571 572 static ::rtl::OUString getLastSyncFileURLFromUserInstallation() 573 { 574 ::rtl::OUString aUserBundledPathURL = getUserBundledExtPathURL(); 575 ::sal_Int32 nLastIndex = aUserBundledPathURL.lastIndexOf('/'); 576 577 ::rtl::OUStringBuffer aTmp( aUserBundledPathURL ); 578 579 if ( nLastIndex != aUserBundledPathURL.getLength()-1 ) 580 aTmp.appendAscii( "/" ); 581 aTmp.appendAscii( pLastSyncFileName ); 582 583 return aTmp.makeStringAndClear(); 584 } 585 //Checks if the argument src is the folder of the help or configuration 586 //backend in the prereg folder 587 static bool excludeTmpFilesAndFolders(const rtl::OUString & src) 588 { 589 const char helpBackend[] = "com.sun.star.comp.deployment.help.PackageRegistryBackend"; 590 const char configBackend[] = "com.sun.star.comp.deployment.configuration.PackageRegistryBackend"; 591 if (src.endsWithAsciiL(helpBackend, sizeof(helpBackend) - 1 ) 592 || src.endsWithAsciiL(configBackend, sizeof(configBackend) - 1)) 593 { 594 return true; 595 } 596 return false; 597 } 598 599 //If we are about to copy the contents of some special folder as determined 600 //by excludeTmpFilesAndFolders, then we omit those files or folders with a name 601 //derived from temporary folders. 602 static bool isExcludedFileOrFolder( const rtl::OUString & name) 603 { 604 char const * allowed[] = { 605 "backenddb.xml", 606 "configmgr.ini", 607 "registered_packages.db" 608 }; 609 610 const unsigned int size = sizeof(allowed) / sizeof (char const *); 611 bool bExclude = true; 612 for (unsigned int i= 0; i < size; i ++) 613 { 614 ::rtl::OUString allowedName = ::rtl::OUString::createFromAscii(allowed[i]); 615 if (allowedName.equals(name)) 616 { 617 bExclude = false; 618 break; 619 } 620 } 621 return bExclude; 622 } 623 624 static osl::FileBase::RC copy_bundled_recursive( 625 const rtl::OUString& srcUnqPath, 626 const rtl::OUString& dstUnqPath, 627 sal_Int32 TypeToCopy ) 628 throw() 629 { 630 osl::FileBase::RC err = osl::FileBase::E_None; 631 632 if( TypeToCopy == -1 ) // Document 633 { 634 err = osl::File::copy( srcUnqPath,dstUnqPath ); 635 } 636 else if( TypeToCopy == +1 ) // Folder 637 { 638 osl::Directory aDir( srcUnqPath ); 639 err = aDir.open(); 640 if ( err != osl::FileBase::E_None ) 641 return err; 642 643 err = osl::Directory::create( dstUnqPath ); 644 osl::FileBase::RC next = err; 645 if( err == osl::FileBase::E_None || 646 err == osl::FileBase::E_EXIST ) 647 { 648 err = osl::FileBase::E_None; 649 sal_Int32 n_Mask = FileStatusMask_FileURL | FileStatusMask_FileName | FileStatusMask_Type; 650 651 osl::DirectoryItem aDirItem; 652 bool bExcludeFiles = excludeTmpFilesAndFolders(srcUnqPath); 653 654 while( err == osl::FileBase::E_None && ( next = aDir.getNextItem( aDirItem ) ) == osl::FileBase::E_None ) 655 { 656 sal_Bool IsDoc = false; 657 sal_Bool bFilter = false; 658 osl::FileStatus aFileStatus( n_Mask ); 659 aDirItem.getFileStatus( aFileStatus ); 660 if( aFileStatus.isValid( FileStatusMask_Type ) ) 661 IsDoc = aFileStatus.getFileType() == osl::FileStatus::Regular; 662 663 // Getting the information for the next recursive copy 664 sal_Int32 newTypeToCopy = IsDoc ? -1 : +1; 665 666 rtl::OUString newSrcUnqPath; 667 if( aFileStatus.isValid( FileStatusMask_FileURL ) ) 668 newSrcUnqPath = aFileStatus.getFileURL(); 669 670 rtl::OUString newDstUnqPath = dstUnqPath; 671 rtl::OUString tit; 672 if( aFileStatus.isValid( FileStatusMask_FileName ) ) 673 { 674 ::rtl::OUString aFileName = aFileStatus.getFileName(); 675 tit = rtl::Uri::encode( aFileName, 676 rtl_UriCharClassPchar, 677 rtl_UriEncodeIgnoreEscapes, 678 RTL_TEXTENCODING_UTF8 ); 679 680 // Special treatment for "lastsychronized" file. Must not be 681 // copied from the bundled folder! 682 //Also do not copy *.tmp files and *.tmp_ folders. This affects the files/folders 683 //from the help and configuration backend 684 if ( IsDoc && (aFileName.equalsAscii( pLastSyncFileName ) 685 || bExcludeFiles && isExcludedFileOrFolder(aFileName))) 686 bFilter = true; 687 else if (!IsDoc && bExcludeFiles && isExcludedFileOrFolder(aFileName)) 688 bFilter = true; 689 } 690 691 if( newDstUnqPath.lastIndexOf( sal_Unicode('/') ) != newDstUnqPath.getLength()-1 ) 692 newDstUnqPath += rtl::OUString::createFromAscii( "/" ); 693 694 newDstUnqPath += tit; 695 696 if (( newSrcUnqPath != dstUnqPath ) && !bFilter ) 697 err = copy_bundled_recursive( newSrcUnqPath,newDstUnqPath, newTypeToCopy ); 698 } 699 700 if( err == osl::FileBase::E_None && next != osl::FileBase::E_NOENT ) 701 err = next; 702 } 703 aDir.close(); 704 } 705 706 return err; 707 } 708 709 Desktop::Desktop() 710 : m_bServicesRegistered( false ) 711 , m_aBootstrapError( BE_OK ) 712 , m_pLockfile( NULL ) 713 { 714 RTL_LOGFILE_TRACE( "desktop (cd100003) ::Desktop::Desktop" ); 715 } 716 717 Desktop::~Desktop() 718 { 719 } 720 721 void Desktop::Init() 722 { 723 RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::Desktop::Init" ); 724 SetBootstrapStatus(BS_OK); 725 726 // Check for lastsynchronized file for bundled extensions in the user directory 727 // and test if synchronzation is necessary! 728 { 729 ::rtl::OUString aUserLastSyncFilePathURL = getLastSyncFileURLFromUserInstallation(); 730 ::rtl::OUString aPreregSyncFilePathURL = getLastSyncFileURLFromBrandInstallation(); 731 732 if ( needsSynchronization( aPreregSyncFilePathURL, aUserLastSyncFilePathURL )) 733 { 734 rtl::OUString aUserPath = getUserBundledExtPathURL(); 735 rtl::OUString aPreregBundledPath = getBrandSharePreregBundledPathURL(); 736 737 // copy bundled folder to the user directory 738 osl::FileBase::RC rc = osl::Directory::createPath(aUserPath); 739 (void) rc; 740 copy_bundled_recursive( aPreregBundledPath, aUserPath, +1 ); 741 } 742 } 743 744 // create service factory... 745 Reference < XMultiServiceFactory > rSMgr = CreateApplicationServiceManager(); 746 if( rSMgr.is() ) 747 { 748 ::comphelper::setProcessServiceFactory( rSMgr ); 749 } 750 else 751 { 752 SetBootstrapError( BE_UNO_SERVICEMANAGER ); 753 } 754 755 if ( GetBootstrapError() == BE_OK ) 756 { 757 // prepare language 758 if ( !LanguageSelection::prepareLanguage() ) 759 { 760 if ( LanguageSelection::getStatus() == LanguageSelection::LS_STATUS_CANNOT_DETERMINE_LANGUAGE ) 761 SetBootstrapError( BE_LANGUAGE_MISSING ); 762 else 763 SetBootstrapError( BE_OFFICECONFIG_BROKEN ); 764 } 765 } 766 767 if ( GetBootstrapError() == BE_OK ) 768 { 769 CommandLineArgs* pCmdLineArgs = GetCommandLineArgs(); 770 #ifdef UNX 771 // check whether we need to print cmdline help 772 if ( pCmdLineArgs->IsHelp() ) { 773 displayCmdlineHelp(); 774 SetBootstrapStatus(BS_TERMINATE); 775 } 776 #endif 777 // start ipc thread only for non-remote offices 778 RTL_LOGFILE_CONTEXT( aLog2, "desktop (cd100003) ::OfficeIPCThread::EnableOfficeIPCThread" ); 779 OfficeIPCThread::Status aStatus = OfficeIPCThread::EnableOfficeIPCThread(); 780 if ( aStatus == OfficeIPCThread::IPC_STATUS_BOOTSTRAP_ERROR ) 781 { 782 SetBootstrapError( BE_PATHINFO_MISSING ); 783 } 784 else if ( aStatus == OfficeIPCThread::IPC_STATUS_2ND_OFFICE ) 785 { 786 // 2nd office startup should terminate after sending cmdlineargs through pipe 787 SetBootstrapStatus(BS_TERMINATE); 788 } 789 else if ( pCmdLineArgs->IsHelp() ) 790 { 791 // disable IPC thread in an instance that is just showing a help message 792 OfficeIPCThread::DisableOfficeIPCThread(); 793 } 794 pSignalHandler = new SalMainPipeExchangeSignalHandler; 795 } 796 } 797 798 void Desktop::DeInit() 799 { 800 RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::Desktop::DeInit" ); 801 802 try { 803 // instead of removing of the configManager just let it commit all the changes 804 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- store config items" ); 805 utl::ConfigManager::GetConfigManager()->StoreConfigItems(); 806 FlushConfiguration(); 807 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- store config items" ); 808 809 // close splashscreen if it's still open 810 CloseSplashScreen(); 811 Reference<XMultiServiceFactory> xXMultiServiceFactory(::comphelper::getProcessServiceFactory()); 812 DestroyApplicationServiceManager( xXMultiServiceFactory ); 813 // nobody should get a destroyd service factory... 814 ::comphelper::setProcessServiceFactory( NULL ); 815 816 // clear lockfile 817 if (m_pLockfile != NULL) 818 m_pLockfile->clean(); 819 820 OfficeIPCThread::DisableOfficeIPCThread(); 821 if( pSignalHandler ) 822 DELETEZ( pSignalHandler ); 823 } catch (RuntimeException&) { 824 // someone threw an exception during shutdown 825 // this will leave some garbage behind.. 826 } 827 828 RTL_LOGFILE_CONTEXT_TRACE( aLog, "FINISHED WITH Destop::DeInit" ); 829 } 830 831 sal_Bool Desktop::QueryExit() 832 { 833 try 834 { 835 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- store config items" ); 836 utl::ConfigManager::GetConfigManager()->StoreConfigItems(); 837 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- store config items" ); 838 } 839 catch ( RuntimeException& ) 840 { 841 } 842 843 const sal_Char SUSPEND_QUICKSTARTVETO[] = "SuspendQuickstartVeto"; 844 845 Reference< ::com::sun::star::frame::XDesktop > 846 xDesktop( ::comphelper::getProcessServiceFactory()->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), 847 UNO_QUERY ); 848 849 Reference < ::com::sun::star::beans::XPropertySet > xPropertySet( xDesktop, UNO_QUERY ); 850 if ( xPropertySet.is() ) 851 { 852 Any a; 853 a <<= (sal_Bool)sal_True; 854 xPropertySet->setPropertyValue( OUSTRING(RTL_CONSTASCII_USTRINGPARAM( SUSPEND_QUICKSTARTVETO )), a ); 855 } 856 857 sal_Bool bExit = ( !xDesktop.is() || xDesktop->terminate() ); 858 859 860 if ( !bExit && xPropertySet.is() ) 861 { 862 Any a; 863 a <<= (sal_Bool)sal_False; 864 xPropertySet->setPropertyValue( OUSTRING(RTL_CONSTASCII_USTRINGPARAM( SUSPEND_QUICKSTARTVETO )), a ); 865 } 866 else 867 { 868 FlushConfiguration(); 869 try 870 { 871 // it is no problem to call DisableOfficeIPCThread() more than once 872 // it also looks to be threadsafe 873 OfficeIPCThread::DisableOfficeIPCThread(); 874 } 875 catch ( RuntimeException& ) 876 { 877 } 878 879 if (m_pLockfile != NULL) m_pLockfile->clean(); 880 } 881 882 return bExit; 883 } 884 885 void Desktop::HandleBootstrapPathErrors( ::utl::Bootstrap::Status aBootstrapStatus, const OUString& aDiagnosticMessage ) 886 { 887 if ( aBootstrapStatus != ::utl::Bootstrap::DATA_OK ) 888 { 889 sal_Bool bWorkstationInstallation = sal_False; 890 ::rtl::OUString aBaseInstallURL; 891 ::rtl::OUString aUserInstallURL; 892 ::rtl::OUString aProductKey; 893 ::rtl::OUString aTemp; 894 ::vos::OStartupInfo aInfo; 895 896 aInfo.getExecutableFile( aProductKey ); 897 sal_uInt32 lastIndex = aProductKey.lastIndexOf('/'); 898 if ( lastIndex > 0 ) 899 aProductKey = aProductKey.copy( lastIndex+1 ); 900 901 aTemp = ::utl::Bootstrap::getProductKey( aProductKey ); 902 if ( aTemp.getLength() > 0 ) 903 aProductKey = aTemp; 904 905 ::utl::Bootstrap::PathStatus aBaseInstallStatus = ::utl::Bootstrap::locateBaseInstallation( aBaseInstallURL ); 906 ::utl::Bootstrap::PathStatus aUserInstallStatus = ::utl::Bootstrap::locateUserInstallation( aUserInstallURL ); 907 908 if (( aBaseInstallStatus == ::utl::Bootstrap::PATH_EXISTS && 909 aUserInstallStatus == ::utl::Bootstrap::PATH_EXISTS )) 910 { 911 if ( aBaseInstallURL != aUserInstallURL ) 912 bWorkstationInstallation = sal_True; 913 } 914 915 OUString aMessage; 916 OUStringBuffer aBuffer( 100 ); 917 aBuffer.append( aDiagnosticMessage ); 918 919 aBuffer.appendAscii( "\n" ); 920 921 ErrorBox aBootstrapFailedBox( NULL, WB_OK, aMessage ); 922 aBootstrapFailedBox.SetText( aProductKey ); 923 aBootstrapFailedBox.Execute(); 924 } 925 } 926 927 // Create a error message depending on bootstrap failure code and an optional file url 928 ::rtl::OUString Desktop::CreateErrorMsgString( 929 utl::Bootstrap::FailureCode nFailureCode, 930 const ::rtl::OUString& aFileURL ) 931 { 932 OUString aMsg; 933 OUString aFilePath; 934 sal_Bool bFileInfo = sal_True; 935 936 switch ( nFailureCode ) 937 { 938 /// the shared installation directory could not be located 939 case ::utl::Bootstrap::MISSING_INSTALL_DIRECTORY: 940 { 941 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_PATH_INVALID, 942 OUString( RTL_CONSTASCII_USTRINGPARAM( "The installation path is not available." )) ); 943 bFileInfo = sal_False; 944 } 945 break; 946 947 /// the bootstrap INI file could not be found or read 948 case ::utl::Bootstrap::MISSING_BOOTSTRAP_FILE: 949 { 950 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_FILE_MISSING, 951 OUString( RTL_CONSTASCII_USTRINGPARAM( "The configuration file \"$1\" is missing." )) ); 952 } 953 break; 954 955 /// the bootstrap INI is missing a required entry 956 /// the bootstrap INI contains invalid data 957 case ::utl::Bootstrap::MISSING_BOOTSTRAP_FILE_ENTRY: 958 case ::utl::Bootstrap::INVALID_BOOTSTRAP_FILE_ENTRY: 959 { 960 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_FILE_CORRUPT, 961 OUString( RTL_CONSTASCII_USTRINGPARAM( "The configuration file \"$1\" is corrupt." )) ); 962 } 963 break; 964 965 /// the version locator INI file could not be found or read 966 case ::utl::Bootstrap::MISSING_VERSION_FILE: 967 { 968 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_FILE_MISSING, 969 OUString( RTL_CONSTASCII_USTRINGPARAM( "The configuration file \"$1\" is missing." )) ); 970 } 971 break; 972 973 /// the version locator INI has no entry for this version 974 case ::utl::Bootstrap::MISSING_VERSION_FILE_ENTRY: 975 { 976 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_NO_SUPPORT, 977 OUString( RTL_CONSTASCII_USTRINGPARAM( "The main configuration file \"$1\" does not support the current version." )) ); 978 } 979 break; 980 981 /// the user installation directory does not exist 982 case ::utl::Bootstrap::MISSING_USER_DIRECTORY: 983 { 984 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_DIR_MISSING, 985 OUString( RTL_CONSTASCII_USTRINGPARAM( "The configuration directory \"$1\" is missing." )) ); 986 } 987 break; 988 989 /// some bootstrap data was invalid in unexpected ways 990 case ::utl::Bootstrap::INVALID_BOOTSTRAP_DATA: 991 { 992 aMsg = GetMsgString( STR_BOOTSTRAP_ERR_INTERNAL, 993 OUString( RTL_CONSTASCII_USTRINGPARAM( "An internal failure occurred." )) ); 994 bFileInfo = sal_False; 995 } 996 break; 997 998 case ::utl::Bootstrap::INVALID_VERSION_FILE_ENTRY: 999 { 1000 // This needs to be improved, see #i67575#: 1001 aMsg = OUString( 1002 RTL_CONSTASCII_USTRINGPARAM( "Invalid version file entry" ) ); 1003 bFileInfo = sal_False; 1004 } 1005 break; 1006 1007 case ::utl::Bootstrap::NO_FAILURE: 1008 { 1009 OSL_ASSERT(false); 1010 } 1011 break; 1012 } 1013 1014 if ( bFileInfo ) 1015 { 1016 String aMsgString( aMsg ); 1017 1018 osl::File::getSystemPathFromFileURL( aFileURL, aFilePath ); 1019 1020 aMsgString.SearchAndReplaceAscii( "$1", aFilePath ); 1021 aMsg = aMsgString; 1022 } 1023 1024 return MakeStartupErrorMessage( aMsg ); 1025 } 1026 1027 void Desktop::HandleBootstrapErrors( BootstrapError aBootstrapError ) 1028 { 1029 if ( aBootstrapError == BE_PATHINFO_MISSING ) 1030 { 1031 OUString aErrorMsg; 1032 OUString aBuffer; 1033 utl::Bootstrap::Status aBootstrapStatus; 1034 utl::Bootstrap::FailureCode nFailureCode; 1035 1036 aBootstrapStatus = ::utl::Bootstrap::checkBootstrapStatus( aBuffer, nFailureCode ); 1037 if ( aBootstrapStatus != ::utl::Bootstrap::DATA_OK ) 1038 { 1039 switch ( nFailureCode ) 1040 { 1041 case ::utl::Bootstrap::MISSING_INSTALL_DIRECTORY: 1042 case ::utl::Bootstrap::INVALID_BOOTSTRAP_DATA: 1043 { 1044 aErrorMsg = CreateErrorMsgString( nFailureCode, OUString() ); 1045 } 1046 break; 1047 1048 /// the bootstrap INI file could not be found or read 1049 /// the bootstrap INI is missing a required entry 1050 /// the bootstrap INI contains invalid data 1051 case ::utl::Bootstrap::MISSING_BOOTSTRAP_FILE_ENTRY: 1052 case ::utl::Bootstrap::INVALID_BOOTSTRAP_FILE_ENTRY: 1053 case ::utl::Bootstrap::MISSING_BOOTSTRAP_FILE: 1054 { 1055 OUString aBootstrapFileURL; 1056 1057 utl::Bootstrap::locateBootstrapFile( aBootstrapFileURL ); 1058 aErrorMsg = CreateErrorMsgString( nFailureCode, aBootstrapFileURL ); 1059 } 1060 break; 1061 1062 /// the version locator INI file could not be found or read 1063 /// the version locator INI has no entry for this version 1064 /// the version locator INI entry is not a valid directory URL 1065 case ::utl::Bootstrap::INVALID_VERSION_FILE_ENTRY: 1066 case ::utl::Bootstrap::MISSING_VERSION_FILE_ENTRY: 1067 case ::utl::Bootstrap::MISSING_VERSION_FILE: 1068 { 1069 OUString aVersionFileURL; 1070 1071 utl::Bootstrap::locateVersionFile( aVersionFileURL ); 1072 aErrorMsg = CreateErrorMsgString( nFailureCode, aVersionFileURL ); 1073 } 1074 break; 1075 1076 /// the user installation directory does not exist 1077 case ::utl::Bootstrap::MISSING_USER_DIRECTORY: 1078 { 1079 OUString aUserInstallationURL; 1080 1081 utl::Bootstrap::locateUserInstallation( aUserInstallationURL ); 1082 aErrorMsg = CreateErrorMsgString( nFailureCode, aUserInstallationURL ); 1083 } 1084 break; 1085 1086 case ::utl::Bootstrap::NO_FAILURE: 1087 { 1088 OSL_ASSERT(false); 1089 } 1090 break; 1091 } 1092 1093 HandleBootstrapPathErrors( aBootstrapStatus, aErrorMsg ); 1094 } 1095 } 1096 else if ( aBootstrapError == BE_UNO_SERVICEMANAGER || aBootstrapError == BE_UNO_SERVICE_CONFIG_MISSING ) 1097 { 1098 // Uno service manager is not available. VCL needs a uno service manager to display a message box!!! 1099 // Currently we are not able to display a message box with a service manager due to this limitations inside VCL. 1100 1101 // When UNO is not properly initialized, all kinds of things can fail 1102 // and cause the process to crash (e.g., a call to GetMsgString may 1103 // crash when somewhere deep within that call Any::operator <= is used 1104 // with a PropertyValue, and no binary UNO type description for 1105 // PropertyValue is available). To give the user a hint even if 1106 // generating and displaying a message box below crashes, print a 1107 // hard-coded message on stderr first: 1108 fputs( 1109 aBootstrapError == BE_UNO_SERVICEMANAGER 1110 ? ("The application cannot be started. " "\n" 1111 "The component manager is not available." "\n") 1112 // STR_BOOTSTRAP_ERR_CANNOT_START, STR_BOOTSTRAP_ERR_NO_SERVICE 1113 : ("The application cannot be started. " "\n" 1114 "The configuration service is not available." "\n"), 1115 // STR_BOOTSTRAP_ERR_CANNOT_START, 1116 // STR_BOOTSTRAP_ERR_NO_CFG_SERVICE 1117 stderr); 1118 1119 // First sentence. We cannot bootstrap office further! 1120 OUString aMessage; 1121 OUStringBuffer aDiagnosticMessage( 100 ); 1122 1123 OUString aErrorMsg; 1124 1125 if ( aBootstrapError == BE_UNO_SERVICEMANAGER ) 1126 aErrorMsg = GetMsgString( STR_BOOTSTRAP_ERR_NO_SERVICE, 1127 OUString( RTL_CONSTASCII_USTRINGPARAM( "The service manager is not available." )) ); 1128 else 1129 aErrorMsg = GetMsgString( STR_BOOTSTRAP_ERR_NO_CFG_SERVICE, 1130 OUString( RTL_CONSTASCII_USTRINGPARAM( "The configuration service is not available." )) ); 1131 1132 aDiagnosticMessage.append( aErrorMsg ); 1133 aDiagnosticMessage.appendAscii( "\n" ); 1134 1135 // Due to the fact the we haven't a backup applicat.rdb file anymore it is not possible to 1136 // repair the installation with the setup executable besides the office executable. Now 1137 // we have to ask the user to start the setup on CD/installation directory manually!! 1138 OUString aStartSetupManually( GetMsgString( 1139 STR_ASK_START_SETUP_MANUALLY, 1140 OUString( RTL_CONSTASCII_USTRINGPARAM( "Start setup application to repair the installation from CD, or the folder containing the installation packages." )) )); 1141 1142 aDiagnosticMessage.append( aStartSetupManually ); 1143 aMessage = MakeStartupErrorMessage( aDiagnosticMessage.makeStringAndClear() ); 1144 1145 FatalError( aMessage); 1146 } 1147 else if ( aBootstrapError == BE_OFFICECONFIG_BROKEN ) 1148 { 1149 OUString aMessage; 1150 OUStringBuffer aDiagnosticMessage( 100 ); 1151 OUString aErrorMsg; 1152 aErrorMsg = GetMsgString( STR_CONFIG_ERR_ACCESS_GENERAL, 1153 OUString( RTL_CONSTASCII_USTRINGPARAM( "A general error occurred while accessing your central configuration." )) ); 1154 aDiagnosticMessage.append( aErrorMsg ); 1155 aMessage = MakeStartupErrorMessage( aDiagnosticMessage.makeStringAndClear() ); 1156 FatalError(aMessage); 1157 } 1158 else if ( aBootstrapError == BE_USERINSTALL_FAILED ) 1159 { 1160 OUString aMessage; 1161 OUStringBuffer aDiagnosticMessage( 100 ); 1162 OUString aErrorMsg; 1163 aErrorMsg = GetMsgString( STR_BOOTSTRAP_ERR_INTERNAL, 1164 OUString( RTL_CONSTASCII_USTRINGPARAM( "User installation could not be completed" )) ); 1165 aDiagnosticMessage.append( aErrorMsg ); 1166 aMessage = MakeStartupErrorMessage( aDiagnosticMessage.makeStringAndClear() ); 1167 FatalError(aMessage); 1168 } 1169 else if ( aBootstrapError == BE_LANGUAGE_MISSING ) 1170 { 1171 OUString aMessage; 1172 OUStringBuffer aDiagnosticMessage( 100 ); 1173 OUString aErrorMsg; 1174 aErrorMsg = GetMsgString( 1175 //@@@ FIXME: should use an own resource string => #i36213# 1176 STR_BOOTSTRAP_ERR_LANGUAGE_MISSING, 1177 OUString( RTL_CONSTASCII_USTRINGPARAM( 1178 "Language could not be determined." )) ); 1179 aDiagnosticMessage.append( aErrorMsg ); 1180 aMessage = MakeStartupErrorMessage( 1181 aDiagnosticMessage.makeStringAndClear() ); 1182 FatalError(aMessage); 1183 } 1184 else if (( aBootstrapError == BE_USERINSTALL_NOTENOUGHDISKSPACE ) || 1185 ( aBootstrapError == BE_USERINSTALL_NOWRITEACCESS )) 1186 { 1187 OUString aUserInstallationURL; 1188 OUString aUserInstallationPath; 1189 OUString aMessage; 1190 OUString aErrorMsg; 1191 OUStringBuffer aDiagnosticMessage( 100 ); 1192 1193 utl::Bootstrap::locateUserInstallation( aUserInstallationURL ); 1194 1195 if ( aBootstrapError == BE_USERINSTALL_NOTENOUGHDISKSPACE ) 1196 aErrorMsg = GetMsgString( 1197 STR_BOOSTRAP_ERR_NOTENOUGHDISKSPACE, 1198 OUString( RTL_CONSTASCII_USTRINGPARAM( 1199 "User installation could not be completed due to insufficient free disk space." )) ); 1200 else 1201 aErrorMsg = GetMsgString( 1202 STR_BOOSTRAP_ERR_NOACCESSRIGHTS, 1203 OUString( RTL_CONSTASCII_USTRINGPARAM( 1204 "User installation could not be processed due to missing access rights." )) ); 1205 1206 osl::File::getSystemPathFromFileURL( aUserInstallationURL, aUserInstallationPath ); 1207 1208 aDiagnosticMessage.append( aErrorMsg ); 1209 aDiagnosticMessage.append( aUserInstallationPath ); 1210 aMessage = MakeStartupErrorMessage( 1211 aDiagnosticMessage.makeStringAndClear() ); 1212 FatalError(aMessage); 1213 } 1214 1215 return; 1216 } 1217 1218 1219 void Desktop::retrieveCrashReporterState() 1220 { 1221 static const ::rtl::OUString CFG_PACKAGE_RECOVERY = ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery/"); 1222 static const ::rtl::OUString CFG_PATH_CRASHREPORTER = ::rtl::OUString::createFromAscii("CrashReporter" ); 1223 static const ::rtl::OUString CFG_ENTRY_ENABLED = ::rtl::OUString::createFromAscii("Enabled" ); 1224 1225 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 1226 1227 sal_Bool bEnabled( sal_True ); 1228 if ( xSMGR.is() ) 1229 { 1230 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 1231 xSMGR, 1232 CFG_PACKAGE_RECOVERY, 1233 CFG_PATH_CRASHREPORTER, 1234 CFG_ENTRY_ENABLED, 1235 ::comphelper::ConfigurationHelper::E_READONLY); 1236 aVal >>= bEnabled; 1237 } 1238 _bCrashReporterEnabled = bEnabled; 1239 } 1240 1241 sal_Bool Desktop::isUIOnSessionShutdownAllowed() 1242 { 1243 static const ::rtl::OUString CFG_PACKAGE_RECOVERY = ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery/"); 1244 static const ::rtl::OUString CFG_PATH_SESSION = ::rtl::OUString::createFromAscii("SessionShutdown" ); 1245 static const ::rtl::OUString CFG_ENTRY_UIENABLED = ::rtl::OUString::createFromAscii("DocumentStoreUIEnabled" ); 1246 1247 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 1248 1249 sal_Bool bResult = sal_False; 1250 if ( xSMGR.is() ) 1251 { 1252 css::uno::Any aVal = ::comphelper::ConfigurationHelper::readDirectKey( 1253 xSMGR, 1254 CFG_PACKAGE_RECOVERY, 1255 CFG_PATH_SESSION, 1256 CFG_ENTRY_UIENABLED, 1257 ::comphelper::ConfigurationHelper::E_READONLY); 1258 aVal >>= bResult; 1259 } 1260 1261 return bResult; 1262 } 1263 1264 //----------------------------------------------- 1265 /** @short check if crash reporter feature is enabled or 1266 disabled. 1267 */ 1268 sal_Bool Desktop::isCrashReporterEnabled() 1269 { 1270 return _bCrashReporterEnabled; 1271 } 1272 1273 //----------------------------------------------- 1274 /** @short check if recovery must be started or not. 1275 1276 @param bCrashed [boolean ... out!] 1277 the office crashed last times. 1278 But may be there are no recovery data. 1279 Usefull to trigger the error report tool without 1280 showing the recovery UI. 1281 1282 @param bRecoveryDataExists [boolean ... out!] 1283 there exists some recovery data. 1284 1285 @param bSessionDataExists [boolean ... out!] 1286 there exists some session data. 1287 Because the user may be logged out last time from it's 1288 unix session... 1289 */ 1290 void impl_checkRecoveryState(sal_Bool& bCrashed , 1291 sal_Bool& bRecoveryDataExists, 1292 sal_Bool& bSessionDataExists ) 1293 { 1294 static const ::rtl::OUString SERVICENAME_RECOVERYCORE = ::rtl::OUString::createFromAscii("com.sun.star.frame.AutoRecovery"); 1295 static const ::rtl::OUString PROP_CRASHED = ::rtl::OUString::createFromAscii("Crashed" ); 1296 static const ::rtl::OUString PROP_EXISTSRECOVERY = ::rtl::OUString::createFromAscii("ExistsRecoveryData" ); 1297 static const ::rtl::OUString PROP_EXISTSSESSION = ::rtl::OUString::createFromAscii("ExistsSessionData" ); 1298 static const ::rtl::OUString CFG_PACKAGE_RECOVERY = ::rtl::OUString::createFromAscii("org.openoffice.Office.Recovery/"); 1299 static const ::rtl::OUString CFG_PATH_RECOVERYINFO = ::rtl::OUString::createFromAscii("RecoveryInfo" ); 1300 1301 bCrashed = sal_False; 1302 bRecoveryDataExists = sal_False; 1303 bSessionDataExists = sal_False; 1304 1305 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 1306 try 1307 { 1308 css::uno::Reference< css::beans::XPropertySet > xRecovery( 1309 xSMGR->createInstance(SERVICENAME_RECOVERYCORE), 1310 css::uno::UNO_QUERY_THROW); 1311 1312 xRecovery->getPropertyValue(PROP_CRASHED ) >>= bCrashed ; 1313 xRecovery->getPropertyValue(PROP_EXISTSRECOVERY) >>= bRecoveryDataExists; 1314 xRecovery->getPropertyValue(PROP_EXISTSSESSION ) >>= bSessionDataExists ; 1315 } 1316 catch(const css::uno::Exception&) {} 1317 } 1318 1319 //----------------------------------------------- 1320 /* @short start the recovery wizard. 1321 1322 @param bEmergencySave 1323 differs between EMERGENCY_SAVE and RECOVERY 1324 */ 1325 sal_Bool impl_callRecoveryUI(sal_Bool bEmergencySave , 1326 sal_Bool bCrashed , 1327 sal_Bool bExistsRecoveryData) 1328 { 1329 static ::rtl::OUString SERVICENAME_RECOVERYUI = ::rtl::OUString::createFromAscii("com.sun.star.comp.svx.RecoveryUI" ); 1330 static ::rtl::OUString SERVICENAME_URLPARSER = ::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" ); 1331 static ::rtl::OUString COMMAND_EMERGENCYSAVE = ::rtl::OUString::createFromAscii("vnd.sun.star.autorecovery:/doEmergencySave"); 1332 static ::rtl::OUString COMMAND_RECOVERY = ::rtl::OUString::createFromAscii("vnd.sun.star.autorecovery:/doAutoRecovery" ); 1333 static ::rtl::OUString COMMAND_CRASHREPORT = ::rtl::OUString::createFromAscii("vnd.sun.star.autorecovery:/doCrashReport" ); 1334 1335 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 1336 1337 css::uno::Reference< css::frame::XSynchronousDispatch > xRecoveryUI( 1338 xSMGR->createInstance(SERVICENAME_RECOVERYUI), 1339 css::uno::UNO_QUERY_THROW); 1340 1341 css::uno::Reference< css::util::XURLTransformer > xURLParser( 1342 xSMGR->createInstance(SERVICENAME_URLPARSER), 1343 css::uno::UNO_QUERY_THROW); 1344 1345 css::util::URL aURL; 1346 if (bEmergencySave) 1347 aURL.Complete = COMMAND_EMERGENCYSAVE; 1348 else 1349 { 1350 if (bExistsRecoveryData) 1351 aURL.Complete = COMMAND_RECOVERY; 1352 else 1353 if (bCrashed && Desktop::isCrashReporterEnabled() ) 1354 aURL.Complete = COMMAND_CRASHREPORT; 1355 } 1356 1357 sal_Bool bRet = sal_False; 1358 if ( aURL.Complete.getLength() > 0 ) 1359 { 1360 xURLParser->parseStrict(aURL); 1361 1362 css::uno::Any aRet = xRecoveryUI->dispatchWithReturnValue(aURL, css::uno::Sequence< css::beans::PropertyValue >()); 1363 aRet >>= bRet; 1364 } 1365 return bRet; 1366 } 1367 1368 /* 1369 * Save all open documents so they will be reopened 1370 * the next time the application ist started 1371 * 1372 * returns sal_True if at least one document could be saved... 1373 * 1374 */ 1375 1376 sal_Bool Desktop::_bTasksSaved = sal_False; 1377 1378 sal_Bool Desktop::SaveTasks() 1379 { 1380 return impl_callRecoveryUI( 1381 sal_True , // sal_True => force emergency save 1382 sal_False, // 2. and 3. param not used if 1. = true! 1383 sal_False); 1384 } 1385 1386 namespace { 1387 1388 void restartOnMac(bool passArguments) { 1389 #if defined MACOSX 1390 OfficeIPCThread::DisableOfficeIPCThread(); 1391 rtl::OUString execUrl; 1392 OSL_VERIFY(osl_getExecutableFile(&execUrl.pData) == osl_Process_E_None); 1393 rtl::OUString execPath; 1394 rtl::OString execPath8; 1395 if ((osl::FileBase::getSystemPathFromFileURL(execUrl, execPath) 1396 != osl::FileBase::E_None) || 1397 !execPath.convertToString( 1398 &execPath8, osl_getThreadTextEncoding(), 1399 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | 1400 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) 1401 { 1402 std::abort(); 1403 } 1404 std::vector< rtl::OString > args; 1405 args.push_back(execPath8); 1406 bool wait = false; 1407 if (passArguments) { 1408 sal_uInt32 n = osl_getCommandArgCount(); 1409 for (sal_uInt32 i = 0; i < n; ++i) { 1410 rtl::OUString arg; 1411 OSL_VERIFY(osl_getCommandArg(i, &arg.pData) == osl_Process_E_None); 1412 if (arg.matchAsciiL(RTL_CONSTASCII_STRINGPARAM("-accept="))) { 1413 wait = true; 1414 } 1415 rtl::OString arg8; 1416 if (!arg.convertToString( 1417 &arg8, osl_getThreadTextEncoding(), 1418 (RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR | 1419 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))) 1420 { 1421 std::abort(); 1422 } 1423 args.push_back(arg8); 1424 } 1425 } 1426 std::vector< char const * > argPtrs; 1427 for (std::vector< rtl::OString >::iterator i(args.begin()); i != args.end(); 1428 ++i) 1429 { 1430 argPtrs.push_back(i->getStr()); 1431 } 1432 argPtrs.push_back(0); 1433 execv(execPath8.getStr(), const_cast< char ** >(&argPtrs[0])); 1434 if (errno == ENOTSUP) { // happens when multithreaded on OS X < 10.6 1435 pid_t pid = fork(); 1436 if (pid == 0) { 1437 execv(execPath8.getStr(), const_cast< char ** >(&argPtrs[0])); 1438 } else if (pid > 0) { 1439 // Two simultaneously running soffice processes lead to two dock 1440 // icons, so avoid waiting here unless it must be assumed that the 1441 // process invoking soffice itself wants to wait for soffice to 1442 // finish: 1443 if (!wait) { 1444 return; 1445 } 1446 int stat; 1447 if (waitpid(pid, &stat, 0) == pid && WIFEXITED(stat)) { 1448 _exit(WEXITSTATUS(stat)); 1449 } 1450 } 1451 } 1452 std::abort(); 1453 #else 1454 (void) passArguments; // avoid warnings 1455 #endif 1456 } 1457 1458 } 1459 1460 sal_uInt16 Desktop::Exception(sal_uInt16 nError) 1461 { 1462 // protect against recursive calls 1463 static sal_Bool bInException = sal_False; 1464 1465 sal_uInt16 nOldMode = Application::GetSystemWindowMode(); 1466 Application::SetSystemWindowMode( nOldMode & ~SYSTEMWINDOW_MODE_NOAUTOMODE ); 1467 Application::SetDefDialogParent( NULL ); 1468 1469 if ( bInException ) 1470 { 1471 String aDoubleExceptionString; 1472 Application::Abort( aDoubleExceptionString ); 1473 } 1474 1475 bInException = sal_True; 1476 CommandLineArgs* pArgs = GetCommandLineArgs(); 1477 1478 // save all modified documents ... if it's allowed doing so. 1479 sal_Bool bRestart = sal_False; 1480 sal_Bool bAllowRecoveryAndSessionManagement = ( 1481 ( !pArgs->IsNoRestore() ) && // some use cases of office must work without recovery 1482 ( !pArgs->IsHeadless() ) && 1483 ( !pArgs->IsServer() ) && 1484 (( nError & EXC_MAJORTYPE ) != EXC_DISPLAY ) && // recovery cant work without UI ... but UI layer seams to be the reason for this crash 1485 ( Application::IsInExecute() ) // crashes during startup and shutdown should be ignored (they indicates a corrupt installation ...) 1486 ); 1487 if ( bAllowRecoveryAndSessionManagement ) 1488 bRestart = SaveTasks(); 1489 1490 FlushConfiguration(); 1491 1492 switch( nError & EXC_MAJORTYPE ) 1493 { 1494 case EXC_RSCNOTLOADED: 1495 { 1496 String aResExceptionString; 1497 Application::Abort( aResExceptionString ); 1498 break; 1499 } 1500 1501 case EXC_SYSOBJNOTCREATED: 1502 { 1503 String aSysResExceptionString; 1504 Application::Abort( aSysResExceptionString ); 1505 break; 1506 } 1507 1508 default: 1509 { 1510 if (m_pLockfile != NULL) { 1511 m_pLockfile->clean(); 1512 } 1513 if( bRestart ) 1514 { 1515 OfficeIPCThread::DisableOfficeIPCThread(); 1516 if( pSignalHandler ) 1517 DELETEZ( pSignalHandler ); 1518 restartOnMac(false); 1519 _exit( ExitHelper::E_CRASH_WITH_RESTART ); 1520 } 1521 else 1522 { 1523 Application::Abort( String() ); 1524 } 1525 1526 break; 1527 } 1528 } 1529 1530 OSL_ASSERT(false); // unreachable 1531 return 0; 1532 } 1533 1534 void Desktop::AppEvent( const ApplicationEvent& rAppEvent ) 1535 { 1536 HandleAppEvent( rAppEvent ); 1537 } 1538 1539 struct ExecuteGlobals 1540 { 1541 Reference < css::document::XEventListener > xGlobalBroadcaster; 1542 sal_Bool bRestartRequested; 1543 sal_Bool bUseSystemFileDialog; 1544 std::auto_ptr<SvtLanguageOptions> pLanguageOptions; 1545 std::auto_ptr<SvtPathOptions> pPathOptions; 1546 1547 ExecuteGlobals() 1548 : bRestartRequested( sal_False ) 1549 , bUseSystemFileDialog( sal_True ) 1550 {} 1551 }; 1552 1553 static ExecuteGlobals* pExecGlobals = NULL; 1554 1555 void Desktop::Main() 1556 { 1557 pExecGlobals = new ExecuteGlobals(); 1558 1559 RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::Desktop::Main" ); 1560 1561 // Remember current context object 1562 com::sun::star::uno::ContextLayer layer( 1563 com::sun::star::uno::getCurrentContext() ); 1564 1565 BootstrapError eError = GetBootstrapError(); 1566 if ( eError != BE_OK ) 1567 { 1568 HandleBootstrapErrors( eError ); 1569 return; 1570 } 1571 1572 BootstrapStatus eStatus = GetBootstrapStatus(); 1573 if (eStatus == BS_TERMINATE) { 1574 return; 1575 } 1576 1577 // Detect desktop environment - need to do this as early as possible 1578 com::sun::star::uno::setCurrentContext( 1579 new DesktopContext( com::sun::star::uno::getCurrentContext() ) ); 1580 1581 CommandLineArgs* pCmdLineArgs = GetCommandLineArgs(); 1582 1583 // setup configuration error handling 1584 ConfigurationErrorHandler aConfigErrHandler; 1585 if (!ShouldSuppressUI(pCmdLineArgs)) 1586 aConfigErrHandler.activate(); 1587 1588 ResMgr::SetReadStringHook( ReplaceStringHookProc ); 1589 1590 // Startup screen 1591 RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main { OpenSplashScreen" ); 1592 OpenSplashScreen(); 1593 RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main } OpenSplashScreen" ); 1594 1595 { 1596 UserInstall::UserInstallError instErr_fin = UserInstall::finalize(); 1597 if ( instErr_fin != UserInstall::E_None) 1598 { 1599 OSL_ENSURE(sal_False, "userinstall failed"); 1600 if ( instErr_fin == UserInstall::E_NoDiskSpace ) 1601 HandleBootstrapErrors( BE_USERINSTALL_NOTENOUGHDISKSPACE ); 1602 else if ( instErr_fin == UserInstall::E_NoWriteAccess ) 1603 HandleBootstrapErrors( BE_USERINSTALL_NOWRITEACCESS ); 1604 else 1605 HandleBootstrapErrors( BE_USERINSTALL_FAILED ); 1606 return; 1607 } 1608 // refresh path information 1609 utl::Bootstrap::reloadData(); 1610 SetSplashScreenProgress(25); 1611 } 1612 1613 Reference< XMultiServiceFactory > xSMgr = 1614 ::comphelper::getProcessServiceFactory(); 1615 1616 Reference< ::com::sun::star::task::XRestartManager > xRestartManager; 1617 int nAcquireCount( 0 ); 1618 try 1619 { 1620 RegisterServices( xSMgr ); 1621 1622 //SetSplashScreenProgress(15); 1623 1624 #ifndef UNX 1625 if ( pCmdLineArgs->IsHelp() ) { 1626 displayCmdlineHelp(); 1627 return; 1628 } 1629 #endif 1630 1631 // check user installation directory for lockfile so we can be sure 1632 // there is no other instance using our data files from a remote host 1633 RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main -> Lockfile" ); 1634 m_pLockfile = new Lockfile; 1635 if ( !pCmdLineArgs->IsHeadless() && !pCmdLineArgs->IsInvisible() && 1636 !pCmdLineArgs->IsNoLockcheck() && !m_pLockfile->check( Lockfile_execWarning )) { 1637 // Lockfile exists, and user clicked 'no' 1638 return; 1639 } 1640 RTL_LOGFILE_CONTEXT_TRACE( aLog, "desktop (lo119109) Desktop::Main <- Lockfile" ); 1641 1642 // check if accessibility is enabled but not working and allow to quit 1643 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ GetEnableATToolSupport" ); 1644 if( Application::GetSettings().GetMiscSettings().GetEnableATToolSupport() ) 1645 { 1646 sal_Bool bQuitApp; 1647 1648 if( !InitAccessBridge( true, bQuitApp ) ) 1649 if( bQuitApp ) 1650 return; 1651 } 1652 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} GetEnableATToolSupport" ); 1653 1654 // terminate if requested... 1655 if( pCmdLineArgs->IsTerminateAfterInit() ) return; 1656 1657 1658 // Read the common configuration items for optimization purpose 1659 if ( !InitializeConfiguration() ) return; 1660 1661 //SetSplashScreenProgress(20); 1662 1663 // set static variable to enabled/disable crash reporter 1664 retrieveCrashReporterState(); 1665 if ( !isCrashReporterEnabled() ) 1666 { 1667 osl_setErrorReporting( sal_False ); 1668 // disable stack trace feature 1669 } 1670 1671 // create title string 1672 sal_Bool bCheckOk = sal_False; 1673 ::com::sun::star::lang::Locale aLocale; 1674 String aMgrName = String::CreateFromAscii( "ofa" ); 1675 ResMgr* pLabelResMgr = ResMgr::SearchCreateResMgr( U2S( aMgrName ), aLocale ); 1676 String aTitle = pLabelResMgr ? String( ResId( RID_APPTITLE, *pLabelResMgr ) ) : String(); 1677 delete pLabelResMgr; 1678 1679 // Check for StarOffice/Suite specific extensions runs also with OpenOffice installation sets 1680 OUString aTitleString( aTitle ); 1681 bCheckOk = CheckInstallation( aTitleString ); 1682 if ( !bCheckOk ) 1683 return; 1684 else 1685 aTitle = aTitleString; 1686 1687 #ifdef DBG_UTIL 1688 //include version ID in non product builds 1689 ::rtl::OUString aDefault; 1690 aTitle += DEFINE_CONST_UNICODE(" ["); 1691 String aVerId( utl::Bootstrap::getBuildIdData( aDefault )); 1692 aTitle += aVerId; 1693 aTitle += ']'; 1694 #endif 1695 1696 SetDisplayName( aTitle ); 1697 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ create SvtPathOptions and SvtLanguageOptions" ); 1698 pExecGlobals->pPathOptions.reset( new SvtPathOptions); 1699 SetSplashScreenProgress(40); 1700 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} create SvtPathOptions and SvtLanguageOptions" ); 1701 1702 // Check special env variable #111015# 1703 std::vector< String > aUnrestrictedFolders; 1704 svt::getUnrestrictedFolders( aUnrestrictedFolders ); 1705 1706 if ( aUnrestrictedFolders.size() > 0 ) 1707 { 1708 // Set different working directory. The first entry is 1709 // the new work path. 1710 String aWorkPath = aUnrestrictedFolders[0]; 1711 SvtPathOptions().SetWorkPath( aWorkPath ); 1712 } 1713 1714 // create service for loadin SFX (still needed in startup) 1715 pExecGlobals->xGlobalBroadcaster = Reference < css::document::XEventListener > 1716 ( xSMgr->createInstance( 1717 DEFINE_CONST_UNICODE( "com.sun.star.frame.GlobalEventBroadcaster" ) ), UNO_QUERY ); 1718 1719 /* ensure existance of a default window that messages can be dispatched to 1720 This is for the benefit of testtool which uses PostUserEvent extensively 1721 and else can deadlock while creating this window from another tread while 1722 the main thread is not yet in the event loop. 1723 */ 1724 Application::GetDefaultDevice(); 1725 1726 // initialize test-tool library (if available) 1727 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ tools::InitTestToolLib" ); 1728 tools::InitTestToolLib(); 1729 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} tools::InitTestToolLib" ); 1730 1731 // Check if bundled or shared extensions were added /removed 1732 // and process those extensions (has to be done before checking 1733 // the extension dependencies! 1734 SynchronizeExtensionRepositories(); 1735 bool bAbort = CheckExtensionDependencies(); 1736 if ( bAbort ) 1737 return; 1738 1739 { 1740 ::comphelper::ComponentContext aContext( xSMgr ); 1741 xRestartManager.set( aContext.getSingleton( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.OfficeRestartManager" ) ) ), UNO_QUERY ); 1742 } 1743 1744 // check whether the shutdown is caused by restart 1745 pExecGlobals->bRestartRequested = ( xRestartManager.is() && xRestartManager->isRestartRequested( sal_True ) ); 1746 1747 // First Start Wizard allowed ? 1748 if ( ! pCmdLineArgs->IsNoFirstStartWizard() && !pExecGlobals->bRestartRequested ) 1749 { 1750 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ FirstStartWizard" ); 1751 1752 if (IsFirstStartWizardNeeded()) 1753 { 1754 ::utl::RegOptions().removeReminder(); // remove patch registration reminder 1755 Reference< XJob > xFirstStartJob( xSMgr->createInstance( 1756 DEFINE_CONST_UNICODE( "com.sun.star.comp.desktop.FirstStart" ) ), UNO_QUERY ); 1757 if (xFirstStartJob.is()) 1758 { 1759 #if 0 // license acceptance is not needed for ASL 1760 sal_Bool bDone = sal_False; 1761 Sequence< NamedValue > lArgs(2); 1762 lArgs[0].Name = ::rtl::OUString::createFromAscii("LicenseNeedsAcceptance"); 1763 lArgs[0].Value <<= LicenseNeedsAcceptance(); 1764 lArgs[1].Name = ::rtl::OUString::createFromAscii("LicensePath"); 1765 lArgs[1].Value <<= GetLicensePath(); 1766 1767 xFirstStartJob->execute(lArgs) >>= bDone; 1768 if ( !bDone ) 1769 { 1770 return; 1771 } 1772 #endif // license acceptance is not needed for ASL 1773 } 1774 } 1775 1776 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} FirstStartWizard" ); 1777 } 1778 1779 // keep a language options instance... 1780 pExecGlobals->pLanguageOptions.reset( new SvtLanguageOptions(sal_True)); 1781 1782 if (pExecGlobals->xGlobalBroadcaster.is()) 1783 { 1784 css::document::EventObject aEvent; 1785 aEvent.EventName = ::rtl::OUString::createFromAscii("OnStartApp"); 1786 pExecGlobals->xGlobalBroadcaster->notifyEvent(aEvent); 1787 } 1788 1789 SetSplashScreenProgress(50); 1790 1791 // Backing Component 1792 sal_Bool bCrashed = sal_False; 1793 sal_Bool bExistsRecoveryData = sal_False; 1794 sal_Bool bExistsSessionData = sal_False; 1795 1796 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ impl_checkRecoveryState" ); 1797 impl_checkRecoveryState(bCrashed, bExistsRecoveryData, bExistsSessionData); 1798 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} impl_checkRecoveryState" ); 1799 1800 { 1801 ::comphelper::ComponentContext aContext( xSMgr ); 1802 xRestartManager.set( aContext.getSingleton( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.OfficeRestartManager" ) ) ), UNO_QUERY ); 1803 } 1804 1805 // check whether the shutdown is caused by restart 1806 pExecGlobals->bRestartRequested = ( xRestartManager.is() && xRestartManager->isRestartRequested( sal_True ) ); 1807 1808 if ( pCmdLineArgs->IsHeadless() ) 1809 { 1810 // Ensure that we use not the system file dialogs as 1811 // headless mode relies on Application::EnableHeadlessMode() 1812 // which does only work for VCL dialogs!! 1813 SvtMiscOptions aMiscOptions; 1814 pExecGlobals->bUseSystemFileDialog = aMiscOptions.UseSystemFileDialog(); 1815 aMiscOptions.SetUseSystemFileDialog( sal_False ); 1816 } 1817 1818 if ( !pExecGlobals->bRestartRequested ) 1819 { 1820 if ((!pCmdLineArgs->WantsToLoadDocument() && !pCmdLineArgs->IsInvisible() && !pCmdLineArgs->IsHeadless() ) && 1821 (SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SSTARTMODULE)) && 1822 (!bExistsRecoveryData ) && 1823 (!bExistsSessionData ) && 1824 (!Application::AnyInput( INPUT_APPEVENT ) )) 1825 { 1826 RTL_LOGFILE_CONTEXT_TRACE( aLog, "{ create BackingComponent" ); 1827 Reference< XFrame > xDesktopFrame( xSMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY ); 1828 if (xDesktopFrame.is()) 1829 { 1830 Reference< XFrame > xBackingFrame; 1831 Reference< ::com::sun::star::awt::XWindow > xContainerWindow; 1832 1833 xBackingFrame = xDesktopFrame->findFrame(OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0); 1834 if (xBackingFrame.is()) 1835 xContainerWindow = xBackingFrame->getContainerWindow(); 1836 if (xContainerWindow.is()) 1837 { 1838 // set the WB_EXT_DOCUMENT style. Normally, this is done by the TaskCreator service when a "_blank" 1839 // frame/window is created. Since we do not use the TaskCreator here, we need to mimic its behavior, 1840 // otherwise documents loaded into this frame will later on miss functionality depending on the style. 1841 Window* pContainerWindow = VCLUnoHelper::GetWindow( xContainerWindow ); 1842 OSL_ENSURE( pContainerWindow, "Desktop::Main: no implementation access to the frame's container window!" ); 1843 pContainerWindow->SetExtendedStyle( pContainerWindow->GetExtendedStyle() | WB_EXT_DOCUMENT ); 1844 1845 SetSplashScreenProgress(75); 1846 Sequence< Any > lArgs(1); 1847 lArgs[0] <<= xContainerWindow; 1848 1849 Reference< XController > xBackingComp( 1850 xSMgr->createInstanceWithArguments(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StartModule") ), lArgs), UNO_QUERY); 1851 if (xBackingComp.is()) 1852 { 1853 Reference< ::com::sun::star::awt::XWindow > xBackingWin(xBackingComp, UNO_QUERY); 1854 // Attention: You MUST(!) call setComponent() before you call attachFrame(). 1855 // Because the backing component set the property "IsBackingMode" of the frame 1856 // to true inside attachFrame(). But setComponent() reset this state everytimes ... 1857 xBackingFrame->setComponent(xBackingWin, xBackingComp); 1858 SetSplashScreenProgress(100); 1859 xBackingComp->attachFrame(xBackingFrame); 1860 CloseSplashScreen(); 1861 xContainerWindow->setVisible(sal_True); 1862 } 1863 } 1864 } 1865 RTL_LOGFILE_CONTEXT_TRACE( aLog, "} create BackingComponent" ); 1866 } 1867 } 1868 } 1869 catch ( com::sun::star::lang::WrappedTargetException& wte ) 1870 { 1871 com::sun::star::uno::Exception te; 1872 wte.TargetException >>= te; 1873 FatalError( MakeStartupConfigAccessErrorMessage(wte.Message + te.Message) ); 1874 return; 1875 } 1876 catch ( com::sun::star::uno::Exception& e ) 1877 { 1878 FatalError( MakeStartupErrorMessage(e.Message) ); 1879 return; 1880 } 1881 1882 SvtFontSubstConfig().Apply(); 1883 1884 SvtTabAppearanceCfg aAppearanceCfg; 1885 aAppearanceCfg.SetInitialized(); 1886 aAppearanceCfg.SetApplicationDefaults( this ); 1887 SvtAccessibilityOptions aOptions; 1888 aOptions.SetVCLSettings(); 1889 1890 if ( !pExecGlobals->bRestartRequested ) 1891 { 1892 Application::SetFilterHdl( LINK( this, Desktop, ImplInitFilterHdl ) ); 1893 sal_Bool bTerminateRequested = sal_False; 1894 1895 // Preload function depends on an initialized sfx application! 1896 SetSplashScreenProgress(75); 1897 1898 // use system window dialogs 1899 Application::SetSystemWindowMode( SYSTEMWINDOW_MODE_DIALOG ); 1900 1901 // SetSplashScreenProgress(80); 1902 1903 if ( !bTerminateRequested && !pCmdLineArgs->IsInvisible() && 1904 !pCmdLineArgs->IsNoQuickstart() ) 1905 InitializeQuickstartMode( xSMgr ); 1906 1907 RTL_LOGFILE_CONTEXT( aLog2, "desktop (cd100003) createInstance com.sun.star.frame.Desktop" ); 1908 try 1909 { 1910 Reference< XDesktop > xDesktop( xSMgr->createInstance( 1911 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ))), UNO_QUERY ); 1912 if ( xDesktop.is() ) 1913 xDesktop->addTerminateListener( new OfficeIPCThreadController ); 1914 SetSplashScreenProgress(100); 1915 } 1916 catch ( com::sun::star::uno::Exception& e ) 1917 { 1918 FatalError( MakeStartupErrorMessage(e.Message) ); 1919 return; 1920 } 1921 1922 // Post user event to startup first application component window 1923 // We have to send this OpenClients message short before execute() to 1924 // minimize the risk that this message overtakes type detection contruction!! 1925 Application::PostUserEvent( LINK( this, Desktop, OpenClients_Impl ) ); 1926 1927 // Post event to enable acceptors 1928 Application::PostUserEvent( LINK( this, Desktop, EnableAcceptors_Impl) ); 1929 1930 // The configuration error handler currently is only for startup 1931 aConfigErrHandler.deactivate(); 1932 1933 // Acquire solar mutex just before we enter our message loop 1934 if ( nAcquireCount ) 1935 Application::AcquireSolarMutex( nAcquireCount ); 1936 1937 // call Application::Execute to process messages in vcl message loop 1938 RTL_LOGFILE_PRODUCT_TRACE( "PERFORMANCE - enter Application::Execute()" ); 1939 1940 try 1941 { 1942 // The JavaContext contains an interaction handler which is used when 1943 // the creation of a Java Virtual Machine fails 1944 com::sun::star::uno::ContextLayer layer2( 1945 new svt::JavaContext( com::sun::star::uno::getCurrentContext() ) ); 1946 1947 // check whether the shutdown is caused by restart just before entering the Execute 1948 pExecGlobals->bRestartRequested = pExecGlobals->bRestartRequested || ( xRestartManager.is() && xRestartManager->isRestartRequested( sal_True ) ); 1949 1950 if ( !pExecGlobals->bRestartRequested ) 1951 { 1952 // if this run of the office is triggered by restart, some additional actions should be done 1953 DoRestartActionsIfNecessary( !pCmdLineArgs->IsInvisible() && !pCmdLineArgs->IsNoQuickstart() ); 1954 1955 Execute(); 1956 } 1957 } 1958 catch(const com::sun::star::document::CorruptedFilterConfigurationException& exFilterCfg) 1959 { 1960 OfficeIPCThread::SetDowning(); 1961 FatalError( MakeStartupErrorMessage(exFilterCfg.Message) ); 1962 } 1963 catch(const com::sun::star::configuration::CorruptedConfigurationException& exAnyCfg) 1964 { 1965 OfficeIPCThread::SetDowning(); 1966 FatalError( MakeStartupErrorMessage(exAnyCfg.Message) ); 1967 } 1968 } 1969 // CAUTION: you do not necessarily get here e.g. on the Mac. 1970 // please put all deinitialization code into doShutdown 1971 doShutdown(); 1972 } 1973 1974 void Desktop::doShutdown() 1975 { 1976 if( ! pExecGlobals ) 1977 return; 1978 1979 if ( pExecGlobals->bRestartRequested ) 1980 SetRestartState(); 1981 1982 if (pExecGlobals->xGlobalBroadcaster.is()) 1983 { 1984 css::document::EventObject aEvent; 1985 aEvent.EventName = ::rtl::OUString::createFromAscii("OnCloseApp"); 1986 pExecGlobals->xGlobalBroadcaster->notifyEvent(aEvent); 1987 } 1988 1989 delete pResMgr, pResMgr = NULL; 1990 // Restore old value 1991 CommandLineArgs* pCmdLineArgs = GetCommandLineArgs(); 1992 if ( pCmdLineArgs->IsHeadless() ) 1993 SvtMiscOptions().SetUseSystemFileDialog( pExecGlobals->bUseSystemFileDialog ); 1994 1995 // remove temp directory 1996 RemoveTemporaryDirectory(); 1997 FlushConfiguration(); 1998 // The acceptors in the AcceptorMap must be released (in DeregisterServices) 1999 // with the solar mutex unlocked, to avoid deadlock: 2000 sal_uLong nAcquireCount = Application::ReleaseSolarMutex(); 2001 DeregisterServices(); 2002 Application::AcquireSolarMutex(nAcquireCount); 2003 tools::DeInitTestToolLib(); 2004 // be sure that path/language options gets destroyed before 2005 // UCB is deinitialized 2006 RTL_LOGFILE_CONTEXT_TRACE( aLog, "-> dispose path/language options" ); 2007 pExecGlobals->pLanguageOptions.reset( 0 ); 2008 pExecGlobals->pPathOptions.reset( 0 ); 2009 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- dispose path/language options" ); 2010 2011 RTL_LOGFILE_CONTEXT_TRACE( aLog, "-> deinit ucb" ); 2012 ::ucbhelper::ContentBroker::deinitialize(); 2013 RTL_LOGFILE_CONTEXT_TRACE( aLog, "<- deinit ucb" ); 2014 2015 sal_Bool bRR = pExecGlobals->bRestartRequested; 2016 delete pExecGlobals, pExecGlobals = NULL; 2017 2018 RTL_LOGFILE_CONTEXT_TRACE( aLog, "FINISHED WITH Destop::Main" ); 2019 if ( bRR ) 2020 { 2021 restartOnMac(true); 2022 // wouldn't the solution be more clean if SalMain returns the exit code to the system? 2023 _exit( ExitHelper::E_NORMAL_RESTART ); 2024 } 2025 } 2026 2027 IMPL_LINK( Desktop, ImplInitFilterHdl, ConvertData*, pData ) 2028 { 2029 return GraphicFilter::GetGraphicFilter()->GetFilterCallback().Call( pData ); 2030 } 2031 2032 sal_Bool Desktop::InitializeConfiguration() 2033 { 2034 sal_Bool bOk = sal_False; 2035 2036 try 2037 { 2038 bOk = InitConfiguration(); 2039 } 2040 catch( ::com::sun::star::lang::ServiceNotRegisteredException& ) 2041 { 2042 this->HandleBootstrapErrors( Desktop::BE_UNO_SERVICE_CONFIG_MISSING ); 2043 } 2044 catch( ::com::sun::star::configuration::MissingBootstrapFileException& e ) 2045 { 2046 OUString aMsg( CreateErrorMsgString( utl::Bootstrap::MISSING_BOOTSTRAP_FILE, 2047 e.BootstrapFileURL )); 2048 HandleBootstrapPathErrors( ::utl::Bootstrap::INVALID_USER_INSTALL, aMsg ); 2049 } 2050 catch( ::com::sun::star::configuration::InvalidBootstrapFileException& e ) 2051 { 2052 OUString aMsg( CreateErrorMsgString( utl::Bootstrap::INVALID_BOOTSTRAP_FILE_ENTRY, 2053 e.BootstrapFileURL )); 2054 HandleBootstrapPathErrors( ::utl::Bootstrap::INVALID_BASE_INSTALL, aMsg ); 2055 } 2056 catch( ::com::sun::star::configuration::InstallationIncompleteException& ) 2057 { 2058 OUString aVersionFileURL; 2059 OUString aMsg; 2060 utl::Bootstrap::PathStatus aPathStatus = utl::Bootstrap::locateVersionFile( aVersionFileURL ); 2061 if ( aPathStatus == utl::Bootstrap::PATH_EXISTS ) 2062 aMsg = CreateErrorMsgString( utl::Bootstrap::MISSING_VERSION_FILE_ENTRY, aVersionFileURL ); 2063 else 2064 aMsg = CreateErrorMsgString( utl::Bootstrap::MISSING_VERSION_FILE, aVersionFileURL ); 2065 2066 HandleBootstrapPathErrors( ::utl::Bootstrap::MISSING_USER_INSTALL, aMsg ); 2067 } 2068 catch ( com::sun::star::configuration::backend::BackendAccessException& exception) 2069 { 2070 // [cm122549] It is assumed in this case that the message 2071 // coming from InitConfiguration (in fact CreateApplicationConf...) 2072 // is suitable for display directly. 2073 FatalError( MakeStartupErrorMessage( exception.Message ) ); 2074 } 2075 catch ( com::sun::star::configuration::backend::BackendSetupException& exception) 2076 { 2077 // [cm122549] It is assumed in this case that the message 2078 // coming from InitConfiguration (in fact CreateApplicationConf...) 2079 // is suitable for display directly. 2080 FatalError( MakeStartupErrorMessage( exception.Message ) ); 2081 } 2082 catch ( ::com::sun::star::configuration::CannotLoadConfigurationException& ) 2083 { 2084 OUString aMsg( CreateErrorMsgString( utl::Bootstrap::INVALID_BOOTSTRAP_DATA, 2085 OUString() )); 2086 HandleBootstrapPathErrors( ::utl::Bootstrap::INVALID_BASE_INSTALL, aMsg ); 2087 } 2088 catch( ::com::sun::star::uno::Exception& ) 2089 { 2090 OUString aMsg( CreateErrorMsgString( utl::Bootstrap::INVALID_BOOTSTRAP_DATA, 2091 OUString() )); 2092 HandleBootstrapPathErrors( ::utl::Bootstrap::INVALID_BASE_INSTALL, aMsg ); 2093 } 2094 2095 return bOk; 2096 } 2097 2098 void Desktop::FlushConfiguration() 2099 { 2100 Reference < XFlushable > xCFGFlush( ::utl::ConfigManager::GetConfigManager()->GetConfigurationProvider(), UNO_QUERY ); 2101 if (xCFGFlush.is()) 2102 { 2103 xCFGFlush->flush(); 2104 } 2105 else 2106 { 2107 // because there is no method to flush the condiguration data, we must dispose the ConfigManager 2108 Reference < XComponent > xCFGDispose( ::utl::ConfigManager::GetConfigManager()->GetConfigurationProvider(), UNO_QUERY ); 2109 if (xCFGDispose.is()) 2110 xCFGDispose->dispose(); 2111 } 2112 } 2113 2114 sal_Bool Desktop::InitializeQuickstartMode( Reference< XMultiServiceFactory >& rSMgr ) 2115 { 2116 try 2117 { 2118 // the shutdown icon sits in the systray and allows the user to keep 2119 // the office instance running for quicker restart 2120 // this will only be activated if -quickstart was specified on cmdline 2121 RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) createInstance com.sun.star.office.Quickstart" ); 2122 2123 sal_Bool bQuickstart = GetCommandLineArgs()->IsQuickstart(); 2124 if ( !bQuickstart ) 2125 { 2126 SfxItemSet aOptSet( SFX_APP()->GetPool(), SID_ATTR_QUICKLAUNCHER, SID_ATTR_QUICKLAUNCHER ); 2127 SFX_APP()->GetOptions(aOptSet); 2128 const SfxPoolItem* pItem; 2129 if ( SFX_ITEM_SET == aOptSet.GetItemState( SID_ATTR_QUICKLAUNCHER, sal_False, &pItem ) ) 2130 bQuickstart = ((const SfxBoolItem*)pItem)->GetValue(); 2131 } 2132 2133 Sequence< Any > aSeq( 1 ); 2134 aSeq[0] <<= bQuickstart; 2135 2136 // Try to instanciate quickstart service. This service is not mandatory, so 2137 // do nothing if service is not available 2138 2139 // #i105753# the following if was invented for performance 2140 // unfortunately this broke the QUARTZ behavior which is to always run 2141 // in quickstart mode since Mac applications do not usually quit 2142 // when the last document closes 2143 #ifndef QUARTZ 2144 if ( bQuickstart ) 2145 #endif 2146 { 2147 Reference < XComponent > xQuickstart( rSMgr->createInstanceWithArguments( 2148 DEFINE_CONST_UNICODE( "com.sun.star.office.Quickstart" ), aSeq ), 2149 UNO_QUERY ); 2150 } 2151 return sal_True; 2152 } 2153 catch( ::com::sun::star::uno::Exception& ) 2154 { 2155 return sal_False; 2156 } 2157 } 2158 2159 void Desktop::SystemSettingsChanging( AllSettings& rSettings, Window* ) 2160 { 2161 if ( !SvtTabAppearanceCfg::IsInitialized () ) 2162 return; 2163 2164 # define DRAGFULL_OPTION_ALL \ 2165 ( DRAGFULL_OPTION_WINDOWMOVE | DRAGFULL_OPTION_WINDOWSIZE \ 2166 | DRAGFULL_OPTION_OBJECTMOVE | DRAGFULL_OPTION_OBJECTSIZE \ 2167 | DRAGFULL_OPTION_DOCKING | DRAGFULL_OPTION_SPLIT \ 2168 | DRAGFULL_OPTION_SCROLL ) 2169 # define DRAGFULL_OPTION_NONE ((sal_uInt32)~DRAGFULL_OPTION_ALL) 2170 2171 StyleSettings hStyleSettings = rSettings.GetStyleSettings(); 2172 MouseSettings hMouseSettings = rSettings.GetMouseSettings(); 2173 2174 sal_uInt32 nDragFullOptions = hStyleSettings.GetDragFullOptions(); 2175 2176 SvtTabAppearanceCfg aAppearanceCfg; 2177 sal_uInt16 nGet = aAppearanceCfg.GetDragMode(); 2178 switch ( nGet ) 2179 { 2180 case DragFullWindow: 2181 nDragFullOptions |= DRAGFULL_OPTION_ALL; 2182 break; 2183 case DragFrame: 2184 nDragFullOptions &= DRAGFULL_OPTION_NONE; 2185 break; 2186 case DragSystemDep: 2187 default: 2188 break; 2189 } 2190 2191 sal_uInt32 nFollow = hMouseSettings.GetFollow(); 2192 hMouseSettings.SetFollow( aAppearanceCfg.IsMenuMouseFollow() ? (nFollow|MOUSE_FOLLOW_MENU) : (nFollow&~MOUSE_FOLLOW_MENU)); 2193 rSettings.SetMouseSettings(hMouseSettings); 2194 2195 sal_Bool bUseImagesInMenus = hStyleSettings.GetUseImagesInMenus(); 2196 2197 SvtMenuOptions aMenuOpt; 2198 nGet = aMenuOpt.GetMenuIconsState(); 2199 switch ( nGet ) 2200 { 2201 case 0: 2202 bUseImagesInMenus = sal_False; 2203 break; 2204 case 1: 2205 bUseImagesInMenus = sal_True; 2206 break; 2207 case 2: 2208 default: 2209 break; 2210 } 2211 hStyleSettings.SetUseImagesInMenus(bUseImagesInMenus); 2212 2213 hStyleSettings.SetDragFullOptions( nDragFullOptions ); 2214 rSettings.SetStyleSettings ( hStyleSettings ); 2215 } 2216 2217 // ======================================================================== 2218 IMPL_LINK( Desktop, AsyncInitFirstRun, void*, EMPTYARG ) 2219 { 2220 DoFirstRunInitializations(); 2221 return 0L; 2222 } 2223 2224 // ======================================================================== 2225 2226 class ExitTimer : public Timer 2227 { 2228 public: 2229 ExitTimer() 2230 { 2231 SetTimeout(500); 2232 Start(); 2233 } 2234 virtual void Timeout() 2235 { 2236 exit(42); 2237 } 2238 }; 2239 2240 IMPL_LINK( Desktop, OpenClients_Impl, void*, EMPTYARG ) 2241 { 2242 RTL_LOGFILE_PRODUCT_CONTEXT( aLog, "PERFORMANCE - DesktopOpenClients_Impl()" ); 2243 2244 OpenClients(); 2245 2246 OfficeIPCThread::SetReady(); 2247 2248 // CloseStartupScreen(); 2249 CloseSplashScreen(); 2250 CheckFirstRun( ); 2251 EnableOleAutomation(); 2252 2253 if (getenv ("OOO_EXIT_POST_STARTUP")) 2254 new ExitTimer(); 2255 return 0; 2256 } 2257 2258 // enable acceptos 2259 IMPL_LINK( Desktop, EnableAcceptors_Impl, void*, EMPTYARG ) 2260 { 2261 enableAcceptors(); 2262 return 0; 2263 } 2264 2265 2266 // Registers a COM class factory of the service manager with the windows operating system. 2267 void Desktop::EnableOleAutomation() 2268 { 2269 RTL_LOGFILE_CONTEXT( aLog, "desktop (jl97489) ::Desktop::EnableOleAutomation" ); 2270 #ifdef WNT 2271 Reference< XMultiServiceFactory > xSMgr= comphelper::getProcessServiceFactory(); 2272 xSMgr->createInstance(DEFINE_CONST_UNICODE("com.sun.star.bridge.OleApplicationRegistration")); 2273 xSMgr->createInstance(DEFINE_CONST_UNICODE("com.sun.star.comp.ole.EmbedServer")); 2274 #endif 2275 } 2276 2277 sal_Bool Desktop::CheckOEM() 2278 { 2279 Reference<XMultiServiceFactory> rFactory = ::comphelper::getProcessServiceFactory(); 2280 Reference<XJob> rOemJob(rFactory->createInstance( 2281 OUString::createFromAscii("com.sun.star.office.OEMPreloadJob")), 2282 UNO_QUERY ); 2283 Sequence<NamedValue> args; 2284 sal_Bool bResult = sal_False; 2285 if (rOemJob.is()) { 2286 Any aResult = rOemJob->execute(args); 2287 aResult >>= bResult; 2288 return bResult; 2289 } else { 2290 return sal_True; 2291 } 2292 } 2293 2294 void Desktop::PreloadModuleData( CommandLineArgs* pArgs ) 2295 { 2296 Reference< XMultiServiceFactory > rFactory = ::comphelper::getProcessServiceFactory(); 2297 2298 Sequence < com::sun::star::beans::PropertyValue > args(1); 2299 args[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Hidden")); 2300 args[0].Value <<= sal_True; 2301 Reference < XComponentLoader > xLoader( ::comphelper::getProcessServiceFactory()->createInstance( 2302 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), UNO_QUERY ); 2303 2304 if ( !xLoader.is() ) 2305 return; 2306 2307 if ( pArgs->IsWriter() ) 2308 { 2309 try 2310 { 2311 Reference < ::com::sun::star::util::XCloseable > xDoc( xLoader->loadComponentFromURL( DEFINE_CONST_UNICODE("private:factory/swriter"), 2312 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, args ), UNO_QUERY_THROW ); 2313 xDoc->close( sal_False ); 2314 } 2315 catch ( com::sun::star::uno::Exception& ) 2316 { 2317 } 2318 } 2319 if ( pArgs->IsCalc() ) 2320 { 2321 try 2322 { 2323 Reference < ::com::sun::star::util::XCloseable > xDoc( xLoader->loadComponentFromURL( DEFINE_CONST_UNICODE("private:factory/scalc"), 2324 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, args ), UNO_QUERY_THROW ); 2325 xDoc->close( sal_False ); 2326 } 2327 catch ( com::sun::star::uno::Exception& ) 2328 { 2329 } 2330 } 2331 if ( pArgs->IsDraw() ) 2332 { 2333 try 2334 { 2335 Reference < ::com::sun::star::util::XCloseable > xDoc( xLoader->loadComponentFromURL( DEFINE_CONST_UNICODE("private:factory/sdraw"), 2336 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, args ), UNO_QUERY_THROW ); 2337 xDoc->close( sal_False ); 2338 } 2339 catch ( com::sun::star::uno::Exception& ) 2340 { 2341 } 2342 } 2343 if ( pArgs->IsImpress() ) 2344 { 2345 try 2346 { 2347 Reference < ::com::sun::star::util::XCloseable > xDoc( xLoader->loadComponentFromURL( DEFINE_CONST_UNICODE("private:factory/simpress"), 2348 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_blank")), 0, args ), UNO_QUERY_THROW ); 2349 xDoc->close( sal_False ); 2350 } 2351 catch ( com::sun::star::uno::Exception& ) 2352 { 2353 } 2354 } 2355 } 2356 2357 void Desktop::PreloadConfigurationData() 2358 { 2359 Reference< XMultiServiceFactory > rFactory = ::comphelper::getProcessServiceFactory(); 2360 Reference< XNameAccess > xNameAccess( rFactory->createInstance( 2361 DEFINE_CONST_UNICODE( "com.sun.star.frame.UICommandDescription" )), UNO_QUERY ); 2362 2363 rtl::OUString aWriterDoc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" )); 2364 rtl::OUString aCalcDoc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" )); 2365 rtl::OUString aDrawDoc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" )); 2366 rtl::OUString aImpressDoc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" )); 2367 2368 // preload commands configuration 2369 if ( xNameAccess.is() ) 2370 { 2371 Any a; 2372 Reference< XNameAccess > xCmdAccess; 2373 2374 try 2375 { 2376 a = xNameAccess->getByName( aWriterDoc ); 2377 a >>= xCmdAccess; 2378 if ( xCmdAccess.is() ) 2379 { 2380 xCmdAccess->getByName( DEFINE_CONST_UNICODE( ".uno:BasicShapes" )); 2381 xCmdAccess->getByName( DEFINE_CONST_UNICODE( ".uno:EditGlossary" )); 2382 } 2383 } 2384 catch ( ::com::sun::star::uno::Exception& ) 2385 { 2386 } 2387 2388 try 2389 { 2390 a = xNameAccess->getByName( aCalcDoc ); 2391 a >>= xCmdAccess; 2392 if ( xCmdAccess.is() ) 2393 xCmdAccess->getByName( DEFINE_CONST_UNICODE( ".uno:InsertObjectStarMath" )); 2394 } 2395 catch ( ::com::sun::star::uno::Exception& ) 2396 { 2397 } 2398 2399 try 2400 { 2401 // draw and impress share the same configuration file (DrawImpressCommands.xcu) 2402 a = xNameAccess->getByName( aDrawDoc ); 2403 a >>= xCmdAccess; 2404 if ( xCmdAccess.is() ) 2405 xCmdAccess->getByName( DEFINE_CONST_UNICODE( ".uno:Polygon" )); 2406 } 2407 catch ( ::com::sun::star::uno::Exception& ) 2408 { 2409 } 2410 } 2411 2412 // preload window state configuration 2413 xNameAccess = Reference< XNameAccess >( rFactory->createInstance( 2414 DEFINE_CONST_UNICODE( "com.sun.star.ui.WindowStateConfiguration" )), UNO_QUERY ); 2415 if ( xNameAccess.is() ) 2416 { 2417 Any a; 2418 Reference< XNameAccess > xWindowAccess; 2419 try 2420 { 2421 a = xNameAccess->getByName( aWriterDoc ); 2422 a >>= xWindowAccess; 2423 if ( xWindowAccess.is() ) 2424 xWindowAccess->getByName( DEFINE_CONST_UNICODE( "private:resource/toolbar/standardbar" )); 2425 } 2426 catch ( ::com::sun::star::uno::Exception& ) 2427 { 2428 } 2429 try 2430 { 2431 a = xNameAccess->getByName( aCalcDoc ); 2432 a >>= xWindowAccess; 2433 if ( xWindowAccess.is() ) 2434 xWindowAccess->getByName( DEFINE_CONST_UNICODE( "private:resource/toolbar/standardbar" )); 2435 } 2436 catch ( ::com::sun::star::uno::Exception& ) 2437 { 2438 } 2439 try 2440 { 2441 a = xNameAccess->getByName( aDrawDoc ); 2442 a >>= xWindowAccess; 2443 if ( xWindowAccess.is() ) 2444 xWindowAccess->getByName( DEFINE_CONST_UNICODE( "private:resource/toolbar/standardbar" )); 2445 } 2446 catch ( ::com::sun::star::uno::Exception& ) 2447 { 2448 } 2449 try 2450 { 2451 a = xNameAccess->getByName( aImpressDoc ); 2452 a >>= xWindowAccess; 2453 if ( xWindowAccess.is() ) 2454 xWindowAccess->getByName( DEFINE_CONST_UNICODE( "private:resource/toolbar/standardbar" )); 2455 } 2456 catch ( ::com::sun::star::uno::Exception& ) 2457 { 2458 } 2459 } 2460 2461 // preload user interface element factories 2462 Sequence< Sequence< css::beans::PropertyValue > > aSeqSeqPropValue; 2463 Reference< ::com::sun::star::ui::XUIElementFactoryRegistration > xUIElementFactory( 2464 rFactory->createInstance( 2465 DEFINE_CONST_UNICODE( "com.sun.star.ui.UIElementFactoryManager" )), 2466 UNO_QUERY ); 2467 if ( xUIElementFactory.is() ) 2468 { 2469 try 2470 { 2471 aSeqSeqPropValue = xUIElementFactory->getRegisteredFactories(); 2472 } 2473 catch ( ::com::sun::star::uno::Exception& ) 2474 { 2475 } 2476 } 2477 2478 // preload popup menu controller factories. As all controllers are in the same 2479 // configuration file they also get preloaded! 2480 Reference< ::com::sun::star::frame::XUIControllerRegistration > xPopupMenuControllerFactory( 2481 rFactory->createInstance( 2482 DEFINE_CONST_UNICODE( "com.sun.star.frame.PopupMenuControllerFactory" )), 2483 UNO_QUERY ); 2484 if ( xPopupMenuControllerFactory.is() ) 2485 { 2486 try 2487 { 2488 xPopupMenuControllerFactory->hasController( 2489 DEFINE_CONST_UNICODE( ".uno:CharFontName" ), 2490 OUString() ); 2491 } 2492 catch ( ::com::sun::star::uno::Exception& ) 2493 { 2494 } 2495 } 2496 2497 // preload filter configuration 2498 Sequence< OUString > aSeq; 2499 xNameAccess = Reference< XNameAccess >( rFactory->createInstance( 2500 DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" )), UNO_QUERY ); 2501 if ( xNameAccess.is() ) 2502 { 2503 try 2504 { 2505 aSeq = xNameAccess->getElementNames(); 2506 } 2507 catch ( ::com::sun::star::uno::Exception& ) 2508 { 2509 } 2510 } 2511 2512 // preload type detection configuration 2513 xNameAccess = Reference< XNameAccess >( rFactory->createInstance( 2514 DEFINE_CONST_UNICODE( "com.sun.star.document.TypeDetection" )), UNO_QUERY ); 2515 if ( xNameAccess.is() ) 2516 { 2517 try 2518 { 2519 aSeq = xNameAccess->getElementNames(); 2520 } 2521 catch ( ::com::sun::star::uno::Exception& ) 2522 { 2523 } 2524 } 2525 2526 static const OUString sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) ); 2527 static const OUString sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" ) ); 2528 2529 // get configuration provider 2530 Reference< XMultiServiceFactory > xConfigProvider; 2531 xConfigProvider = Reference< XMultiServiceFactory > ( 2532 rFactory->createInstance( sConfigSrvc ),UNO_QUERY ); 2533 2534 if ( xConfigProvider.is() ) 2535 { 2536 // preload writer configuration 2537 Sequence< Any > theArgs(1); 2538 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Writer/MailMergeWizard" ); 2539 try 2540 { 2541 xNameAccess = Reference< XNameAccess >( 2542 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2543 } 2544 catch (::com::sun::star::uno::Exception& ) 2545 { 2546 } 2547 2548 // WriterWeb 2549 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.WriterWeb/Content" ); 2550 try 2551 { 2552 xNameAccess = Reference< XNameAccess >( 2553 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2554 } 2555 catch (::com::sun::star::uno::Exception& ) 2556 { 2557 } 2558 2559 // preload compatibility 2560 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Compatibility/WriterCompatibilityVersion" ); 2561 try 2562 { 2563 xNameAccess = Reference< XNameAccess >( 2564 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2565 } 2566 catch (::com::sun::star::uno::Exception& ) 2567 { 2568 } 2569 2570 // preload calc configuration 2571 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Calc/Content" ); 2572 try 2573 { 2574 xNameAccess = Reference< XNameAccess >( 2575 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2576 } 2577 catch (::com::sun::star::uno::Exception& ) 2578 { 2579 } 2580 2581 // preload impress configuration 2582 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.UI.Effects/UserInterface" ); 2583 try 2584 { 2585 xNameAccess = Reference< XNameAccess >( 2586 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2587 } 2588 catch (::com::sun::star::uno::Exception& ) 2589 { 2590 } 2591 2592 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Impress/Layout" ); 2593 try 2594 { 2595 xNameAccess = Reference< XNameAccess >( 2596 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2597 } 2598 catch (::com::sun::star::uno::Exception& ) 2599 { 2600 } 2601 2602 // preload draw configuration 2603 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Draw/Layout" ); 2604 try 2605 { 2606 xNameAccess = Reference< XNameAccess >( 2607 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2608 } 2609 catch (::com::sun::star::uno::Exception& ) 2610 { 2611 } 2612 2613 // preload ui configuration 2614 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.UI/FilterClassification" ); 2615 try 2616 { 2617 xNameAccess = Reference< XNameAccess >( 2618 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2619 } 2620 catch (::com::sun::star::uno::Exception& ) 2621 { 2622 } 2623 2624 // preload addons configuration 2625 theArgs[ 0 ] <<= OUString::createFromAscii( "org.openoffice.Office.Addons/AddonUI" ); 2626 try 2627 { 2628 xNameAccess = Reference< XNameAccess >( 2629 xConfigProvider->createInstanceWithArguments( sAccessSrvc, theArgs ), UNO_QUERY ); 2630 } 2631 catch (::com::sun::star::uno::Exception& ) 2632 { 2633 } 2634 } 2635 } 2636 2637 void Desktop::OpenClients() 2638 { 2639 2640 // check if a document has been recovered - if there is one of if a document was loaded by cmdline, no default document 2641 // should be created 2642 Reference < XComponent > xFirst; 2643 sal_Bool bLoaded = sal_False; 2644 2645 CommandLineArgs* pArgs = GetCommandLineArgs(); 2646 SvtInternalOptions aInternalOptions; 2647 2648 Reference<XMultiServiceFactory> rFactory = ::comphelper::getProcessServiceFactory(); 2649 2650 if (!pArgs->IsQuickstart()) { 2651 sal_Bool bShowHelp = sal_False; 2652 ::rtl::OUStringBuffer aHelpURLBuffer; 2653 if (pArgs->IsHelpWriter()) { 2654 bShowHelp = sal_True; 2655 aHelpURLBuffer.appendAscii("vnd.sun.star.help://swriter/start"); 2656 } else if (pArgs->IsHelpCalc()) { 2657 bShowHelp = sal_True; 2658 aHelpURLBuffer.appendAscii("vnd.sun.star.help://scalc/start"); 2659 } else if (pArgs->IsHelpDraw()) { 2660 bShowHelp = sal_True; 2661 aHelpURLBuffer.appendAscii("vnd.sun.star.help://sdraw/start"); 2662 } else if (pArgs->IsHelpImpress()) { 2663 bShowHelp = sal_True; 2664 aHelpURLBuffer.appendAscii("vnd.sun.star.help://simpress/start"); 2665 } else if (pArgs->IsHelpBase()) { 2666 bShowHelp = sal_True; 2667 aHelpURLBuffer.appendAscii("vnd.sun.star.help://sdatabase/start"); 2668 } else if (pArgs->IsHelpBasic()) { 2669 bShowHelp = sal_True; 2670 aHelpURLBuffer.appendAscii("vnd.sun.star.help://sbasic/start"); 2671 } else if (pArgs->IsHelpMath()) { 2672 bShowHelp = sal_True; 2673 aHelpURLBuffer.appendAscii("vnd.sun.star.help://smath/start"); 2674 } 2675 if (bShowHelp) { 2676 Help *pHelp = Application::GetHelp(); 2677 2678 Any aRet = ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::LOCALE ); 2679 rtl::OUString aTmp; 2680 aRet >>= aTmp; 2681 aHelpURLBuffer.appendAscii("?Language="); 2682 aHelpURLBuffer.append(aTmp); 2683 #if defined UNX 2684 aHelpURLBuffer.appendAscii("&System=UNX"); 2685 #elif defined WNT 2686 aHelpURLBuffer.appendAscii("&System=WIN"); 2687 #elif defined OS2 2688 aHelpURLBuffer.appendAscii("&System=OS2"); 2689 #endif 2690 pHelp->Start(aHelpURLBuffer.makeStringAndClear(), NULL); 2691 return; 2692 } 2693 } 2694 else 2695 { 2696 OUString aIniName; 2697 ::vos::OStartupInfo aInfo; 2698 2699 aInfo.getExecutableFile( aIniName ); 2700 sal_uInt32 lastIndex = aIniName.lastIndexOf('/'); 2701 if ( lastIndex > 0 ) 2702 { 2703 aIniName = aIniName.copy( 0, lastIndex+1 ); 2704 aIniName += OUString( RTL_CONSTASCII_USTRINGPARAM( "perftune" )); 2705 #if defined(WNT) || defined(OS2) 2706 aIniName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".ini" )); 2707 #else 2708 aIniName += OUString( RTL_CONSTASCII_USTRINGPARAM( "rc" )); 2709 #endif 2710 } 2711 2712 rtl::Bootstrap aPerfTuneIniFile( aIniName ); 2713 2714 OUString aDefault( RTL_CONSTASCII_USTRINGPARAM( "0" )); 2715 OUString aPreloadData; 2716 2717 aPerfTuneIniFile.getFrom( OUString( RTL_CONSTASCII_USTRINGPARAM( "QuickstartPreloadConfiguration" )), aPreloadData, aDefault ); 2718 if ( aPreloadData.equalsAscii( "1" )) 2719 { 2720 if ( pArgs->IsWriter() || 2721 pArgs->IsCalc() || 2722 pArgs->IsDraw() || 2723 pArgs->IsImpress() ) 2724 { 2725 PreloadModuleData( pArgs ); 2726 } 2727 2728 PreloadConfigurationData(); 2729 } 2730 } 2731 2732 // Disable AutoSave feature in case "-norestore" or a similare command line switch is set on the command line. 2733 // The reason behind: AutoSave/EmergencySave/AutoRecovery share the same data. 2734 // But the require that all documents, which are saved as backup should exists inside 2735 // memory. May be this mechanism will be inconsistent if the configuration exists ... 2736 // but no document inside memory corrspond to this data. 2737 // Furter it's not acceptable to recover such documents without any UI. It can 2738 // need some time, where the user wont see any results and wait for finishing the office startup ... 2739 sal_Bool bAllowRecoveryAndSessionManagement = ( 2740 ( !pArgs->IsNoRestore() ) && 2741 ( !pArgs->IsHeadless() ) && 2742 ( !pArgs->IsServer() ) 2743 ); 2744 2745 if ( ! bAllowRecoveryAndSessionManagement ) 2746 { 2747 try 2748 { 2749 Reference< XDispatch > xRecovery( 2750 ::comphelper::getProcessServiceFactory()->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.AutoRecovery")) ), 2751 ::com::sun::star::uno::UNO_QUERY_THROW ); 2752 2753 Reference< XURLTransformer > xParser( 2754 ::comphelper::getProcessServiceFactory()->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer")) ), 2755 ::com::sun::star::uno::UNO_QUERY_THROW ); 2756 2757 css::util::URL aCmd; 2758 aCmd.Complete = ::rtl::OUString::createFromAscii("vnd.sun.star.autorecovery:/disableRecovery"); 2759 xParser->parseStrict(aCmd); 2760 2761 xRecovery->dispatch(aCmd, css::uno::Sequence< css::beans::PropertyValue >()); 2762 } 2763 catch(const css::uno::Exception& e) 2764 { 2765 OUString aMessage = OUString::createFromAscii("Could not disable AutoRecovery.\n") 2766 + e.Message; 2767 OSL_ENSURE(sal_False, OUStringToOString(aMessage, RTL_TEXTENCODING_ASCII_US).getStr()); 2768 } 2769 } 2770 else 2771 { 2772 sal_Bool bCrashed = sal_False; 2773 sal_Bool bExistsRecoveryData = sal_False; 2774 sal_Bool bExistsSessionData = sal_False; 2775 2776 impl_checkRecoveryState(bCrashed, bExistsRecoveryData, bExistsSessionData); 2777 2778 if ( !getenv ("OOO_DISABLE_RECOVERY") && 2779 ( ! bLoaded ) && 2780 ( 2781 ( bExistsRecoveryData ) || // => crash with files => recovery 2782 ( bCrashed ) // => crash without files => error report 2783 ) 2784 ) 2785 { 2786 try 2787 { 2788 impl_callRecoveryUI( 2789 sal_False , // false => force recovery instead of emergency save 2790 bCrashed , 2791 bExistsRecoveryData); 2792 /* TODO we cant be shure, that at least one document could be recovered here successfully 2793 So we set bLoaded=sal_True to supress opening of the default document. 2794 But we should make it more safe. Otherwhise we have an office without an UI ... 2795 ... 2796 May be we can check the desktop if some documents are existing there. 2797 */ 2798 Reference< XFramesSupplier > xTasksSupplier( 2799 ::comphelper::getProcessServiceFactory()->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), 2800 ::com::sun::star::uno::UNO_QUERY_THROW ); 2801 Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY_THROW ); 2802 if ( xList->hasElements() ) 2803 bLoaded = sal_True; 2804 } 2805 catch(const css::uno::Exception& e) 2806 { 2807 OUString aMessage = OUString::createFromAscii("Error during recovery\n") 2808 + e.Message; 2809 OSL_ENSURE(sal_False, OUStringToOString(aMessage, RTL_TEXTENCODING_ASCII_US).getStr()); 2810 } 2811 } 2812 2813 Reference< XInitialization > xSessionListener; 2814 try 2815 { 2816 xSessionListener = Reference< XInitialization >(::comphelper::getProcessServiceFactory()->createInstance( 2817 OUString::createFromAscii("com.sun.star.frame.SessionListener")), UNO_QUERY_THROW); 2818 2819 // specifies whether the UI-interaction on Session shutdown is allowed 2820 sal_Bool bAllowUI = isUIOnSessionShutdownAllowed(); 2821 css::beans::NamedValue aProperty( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowUserInteractionOnQuit" ) ), 2822 css::uno::makeAny( bAllowUI ) ); 2823 css::uno::Sequence< css::uno::Any > aArgs( 1 ); 2824 aArgs[0] <<= aProperty; 2825 2826 xSessionListener->initialize( aArgs ); 2827 } 2828 catch(const com::sun::star::uno::Exception& e) 2829 { 2830 OUString aMessage = OUString::createFromAscii("Registration of session listener failed\n") 2831 + e.Message; 2832 OSL_ENSURE(sal_False, OUStringToOString(aMessage, RTL_TEXTENCODING_ASCII_US).getStr()); 2833 } 2834 2835 if ( 2836 ( ! bLoaded ) && 2837 ( bExistsSessionData ) 2838 ) 2839 { 2840 // session management 2841 try 2842 { 2843 Reference< XSessionManagerListener > r(xSessionListener, UNO_QUERY_THROW); 2844 bLoaded = r->doRestore(); 2845 } 2846 catch(const com::sun::star::uno::Exception& e) 2847 { 2848 OUString aMessage = OUString::createFromAscii("Error in session management\n") 2849 + e.Message; 2850 OSL_ENSURE(sal_False, OUStringToOString(aMessage, RTL_TEXTENCODING_ASCII_US).getStr()); 2851 } 2852 } 2853 } 2854 2855 OfficeIPCThread::EnableRequests(); 2856 2857 sal_Bool bShutdown( sal_False ); 2858 if ( !pArgs->IsServer() ) 2859 { 2860 ProcessDocumentsRequest aRequest(pArgs->getCwdUrl()); 2861 aRequest.pcProcessed = NULL; 2862 2863 pArgs->GetOpenList( aRequest.aOpenList ); 2864 pArgs->GetViewList( aRequest.aViewList ); 2865 pArgs->GetStartList( aRequest.aStartList ); 2866 pArgs->GetPrintList( aRequest.aPrintList ); 2867 pArgs->GetPrintToList( aRequest.aPrintToList ); 2868 pArgs->GetPrinterName( aRequest.aPrinterName ); 2869 pArgs->GetForceOpenList( aRequest.aForceOpenList ); 2870 pArgs->GetForceNewList( aRequest.aForceNewList ); 2871 2872 if ( aRequest.aOpenList.getLength() > 0 || 2873 aRequest.aViewList.getLength() > 0 || 2874 aRequest.aStartList.getLength() > 0 || 2875 aRequest.aPrintList.getLength() > 0 || 2876 aRequest.aForceOpenList.getLength() > 0 || 2877 aRequest.aForceNewList.getLength() > 0 || 2878 ( aRequest.aPrintToList.getLength() > 0 && aRequest.aPrinterName.getLength() > 0 )) 2879 { 2880 bLoaded = sal_True; 2881 2882 if ( pArgs->HasModuleParam() ) 2883 { 2884 SvtModuleOptions aOpt; 2885 2886 // Support command line parameters to start a module (as preselection) 2887 if ( pArgs->IsWriter() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) ) 2888 aRequest.aModule = aOpt.GetFactoryName( SvtModuleOptions::E_WRITER ); 2889 else if ( pArgs->IsCalc() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) ) 2890 aRequest.aModule = aOpt.GetFactoryName( SvtModuleOptions::E_CALC ); 2891 else if ( pArgs->IsImpress() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) ) 2892 aRequest.aModule= aOpt.GetFactoryName( SvtModuleOptions::E_IMPRESS ); 2893 else if ( pArgs->IsDraw() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) ) 2894 aRequest.aModule= aOpt.GetFactoryName( SvtModuleOptions::E_DRAW ); 2895 } 2896 2897 // check for printing disabled 2898 if( ( aRequest.aPrintList.getLength() || aRequest.aPrintToList.getLength() ) 2899 && Application::GetSettings().GetMiscSettings().GetDisablePrinting() ) 2900 { 2901 aRequest.aPrintList = rtl::OUString(); 2902 aRequest.aPrintToList = rtl::OUString(); 2903 ResMgr* pDtResMgr = GetDesktopResManager(); 2904 if( pDtResMgr ) 2905 { 2906 ErrorBox aBox( NULL, ResId( EBX_ERR_PRINTDISABLED, *pDtResMgr ) ); 2907 aBox.Execute(); 2908 } 2909 } 2910 2911 // Process request 2912 bShutdown = OfficeIPCThread::ExecuteCmdLineRequests( aRequest ); 2913 } 2914 } 2915 2916 // Don't do anything if we have successfully called terminate at desktop 2917 if ( bShutdown ) 2918 return; 2919 2920 // no default document if a document was loaded by recovery or by command line or if soffice is used as server 2921 Reference< XFramesSupplier > xTasksSupplier( 2922 ::comphelper::getProcessServiceFactory()->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), 2923 ::com::sun::star::uno::UNO_QUERY_THROW ); 2924 Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY_THROW ); 2925 if ( xList->hasElements() || pArgs->IsServer() ) 2926 return; 2927 2928 if ( pArgs->IsQuickstart() || pArgs->IsInvisible() || pArgs->IsBean() || Application::AnyInput( INPUT_APPEVENT ) ) 2929 // soffice was started as tray icon ... 2930 return; 2931 { 2932 OpenDefault(); 2933 } 2934 } 2935 2936 void Desktop::OpenDefault() 2937 { 2938 2939 RTL_LOGFILE_CONTEXT( aLog, "desktop (cd100003) ::Desktop::OpenDefault" ); 2940 2941 ::rtl::OUString aName; 2942 SvtModuleOptions aOpt; 2943 2944 CommandLineArgs* pArgs = GetCommandLineArgs(); 2945 if ( pArgs->IsNoDefault() ) return; 2946 if ( pArgs->HasModuleParam() ) 2947 { 2948 // Support new command line parameters to start a module 2949 if ( pArgs->IsWriter() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) ) 2950 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_WRITER ); 2951 else if ( pArgs->IsCalc() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) ) 2952 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_CALC ); 2953 else if ( pArgs->IsImpress() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) ) 2954 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_IMPRESS ); 2955 else if ( pArgs->IsBase() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) ) 2956 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_DATABASE ); 2957 else if ( pArgs->IsDraw() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) ) 2958 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_DRAW ); 2959 else if ( pArgs->IsMath() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) ) 2960 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_MATH ); 2961 else if ( pArgs->IsGlobal() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) ) 2962 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_WRITERGLOBAL ); 2963 else if ( pArgs->IsWeb() && aOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) ) 2964 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_WRITERWEB ); 2965 } 2966 2967 if ( !aName.getLength() ) 2968 { 2969 // Old way to create a default document 2970 if ( aOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) ) 2971 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_WRITER ); 2972 else if ( aOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) ) 2973 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_CALC ); 2974 else if ( aOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) ) 2975 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_IMPRESS ); 2976 else if ( aOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) ) 2977 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_DATABASE ); 2978 else if ( aOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) ) 2979 aName = aOpt.GetFactoryEmptyDocumentURL( SvtModuleOptions::E_DRAW ); 2980 else 2981 return; 2982 } 2983 2984 ProcessDocumentsRequest aRequest(pArgs->getCwdUrl()); 2985 aRequest.pcProcessed = NULL; 2986 aRequest.aOpenList = aName; 2987 OfficeIPCThread::ExecuteCmdLineRequests( aRequest ); 2988 } 2989 2990 2991 String GetURL_Impl( 2992 const String& rName, boost::optional< rtl::OUString > const & cwdUrl ) 2993 { 2994 // if rName is a vnd.sun.star.script URL do not attempt to parse it 2995 // as INetURLObj does not handle handle there URLs 2996 if (rName.CompareToAscii("vnd.sun.star.script" , 19) == COMPARE_EQUAL) 2997 { 2998 return rName; 2999 } 3000 3001 // dont touch file urls, those should already be in internal form 3002 // they won't get better here (#112849#) 3003 if (rName.CompareToAscii("file:" , 5) == COMPARE_EQUAL) 3004 { 3005 return rName; 3006 } 3007 3008 if ( rName.CompareToAscii("service:" , 8) == COMPARE_EQUAL ) 3009 { 3010 return rName; 3011 } 3012 3013 // Add path seperator to these directory and make given URL (rName) absolute by using of current working directory 3014 // Attention: "setFianlSlash()" is neccessary for calling "smartRel2Abs()"!!! 3015 // Otherwhise last part will be ignored and wrong result will be returned!!! 3016 // "smartRel2Abs()" interpret given URL as file not as path. So he truncate last element to get the base path ... 3017 // But if we add a seperator - he doesn't do it anymore. 3018 INetURLObject aObj; 3019 if (cwdUrl) { 3020 aObj.SetURL(*cwdUrl); 3021 aObj.setFinalSlash(); 3022 } 3023 3024 // Use the provided parameters for smartRel2Abs to support the usage of '%' in system paths. 3025 // Otherwise this char won't get encoded and we are not able to load such files later, 3026 // see #110156# 3027 bool bWasAbsolute; 3028 INetURLObject aURL = aObj.smartRel2Abs( rName, bWasAbsolute, false, INetURLObject::WAS_ENCODED, 3029 RTL_TEXTENCODING_UTF8, true ); 3030 String aFileURL = aURL.GetMainURL(INetURLObject::NO_DECODE); 3031 3032 ::osl::FileStatus aStatus( FileStatusMask_FileURL ); 3033 ::osl::DirectoryItem aItem; 3034 if( ::osl::FileBase::E_None == ::osl::DirectoryItem::get( aFileURL, aItem ) && 3035 ::osl::FileBase::E_None == aItem.getFileStatus( aStatus ) ) 3036 aFileURL = aStatus.getFileURL(); 3037 3038 return aFileURL; 3039 } 3040 3041 void Desktop::HandleAppEvent( const ApplicationEvent& rAppEvent ) 3042 { 3043 if ( rAppEvent.GetEvent() == "APPEAR" && !GetCommandLineArgs()->IsInvisible() ) 3044 { 3045 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 3046 3047 // find active task - the active task is always a visible task 3048 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFramesSupplier > 3049 xDesktop( xSMGR->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), 3050 ::com::sun::star::uno::UNO_QUERY ); 3051 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xTask = xDesktop->getActiveFrame(); 3052 if ( !xTask.is() ) 3053 { 3054 // get any task if there is no active one 3055 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > xList( xDesktop->getFrames(), ::com::sun::star::uno::UNO_QUERY ); 3056 if ( xList->getCount()>0 ) 3057 xList->getByIndex(0) >>= xTask; 3058 } 3059 3060 if ( xTask.is() ) 3061 { 3062 Reference< com::sun::star::awt::XTopWindow > xTop( xTask->getContainerWindow(), UNO_QUERY ); 3063 xTop->toFront(); 3064 } 3065 else 3066 { 3067 // no visible task that could be activated found 3068 Reference< XFrame > xBackingFrame; 3069 Reference< ::com::sun::star::awt::XWindow > xContainerWindow; 3070 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xDesktopFrame( xDesktop, UNO_QUERY ); 3071 3072 xBackingFrame = xDesktopFrame->findFrame(OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" )), 0); 3073 if (xBackingFrame.is()) 3074 xContainerWindow = xBackingFrame->getContainerWindow(); 3075 if (xContainerWindow.is()) 3076 { 3077 Sequence< Any > lArgs(1); 3078 lArgs[0] <<= xContainerWindow; 3079 Reference< XController > xBackingComp( 3080 xSMGR->createInstanceWithArguments(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.StartModule") ), lArgs), 3081 UNO_QUERY); 3082 if (xBackingComp.is()) 3083 { 3084 Reference< ::com::sun::star::awt::XWindow > xBackingWin(xBackingComp, UNO_QUERY); 3085 // Attention: You MUST(!) call setComponent() before you call attachFrame(). 3086 // Because the backing component set the property "IsBackingMode" of the frame 3087 // to true inside attachFrame(). But setComponent() reset this state everytimes ... 3088 xBackingFrame->setComponent(xBackingWin, xBackingComp); 3089 xBackingComp->attachFrame(xBackingFrame); 3090 xContainerWindow->setVisible(sal_True); 3091 3092 Window* pCompWindow = VCLUnoHelper::GetWindow(xBackingFrame->getComponentWindow()); 3093 if (pCompWindow) 3094 pCompWindow->Update(); 3095 } 3096 } 3097 } 3098 } 3099 else if ( rAppEvent.GetEvent() == "QUICKSTART" && !GetCommandLineArgs()->IsInvisible() ) 3100 { 3101 // If the office has been started the second time its command line arguments are sent through a pipe 3102 // connection to the first office. We want to reuse the quickstart option for the first office. 3103 // NOTICE: The quickstart service must be initialized inside the "main thread", so we use the 3104 // application events to do this (they are executed inside main thread)!!! 3105 // Don't start quickstart service if the user specified "-invisible" on the command line! 3106 sal_Bool bQuickstart( sal_True ); 3107 Sequence< Any > aSeq( 1 ); 3108 aSeq[0] <<= bQuickstart; 3109 3110 Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance( 3111 DEFINE_CONST_UNICODE( "com.sun.star.office.Quickstart" )), 3112 UNO_QUERY ); 3113 if ( xQuickstart.is() ) 3114 xQuickstart->initialize( aSeq ); 3115 } 3116 else if ( rAppEvent.GetEvent() == "ACCEPT" ) 3117 { 3118 // every time an accept parameter is used we create an acceptor 3119 // with the corresponding accept-string 3120 OUString aAcceptString(rAppEvent.GetData().GetBuffer()); 3121 createAcceptor(aAcceptString); 3122 } 3123 else if ( rAppEvent.GetEvent() == "UNACCEPT" ) 3124 { 3125 // try to remove corresponding acceptor 3126 OUString aUnAcceptString(rAppEvent.GetData().GetBuffer()); 3127 destroyAcceptor(aUnAcceptString); 3128 } 3129 else if ( rAppEvent.GetEvent() == "SaveDocuments" ) 3130 { 3131 Desktop::_bTasksSaved = sal_False; 3132 Desktop::_bTasksSaved = SaveTasks(); 3133 } 3134 else if ( rAppEvent.GetEvent() == "OPENHELPURL" ) 3135 { 3136 // start help for a specific URL 3137 OUString aHelpURL(rAppEvent.GetData().GetBuffer()); 3138 Help *pHelp = Application::GetHelp(); 3139 pHelp->Start(aHelpURL, NULL); 3140 } 3141 else if ( rAppEvent.GetEvent() == APPEVENT_OPEN_STRING ) 3142 { 3143 OUString aOpenURL(rAppEvent.GetData().GetBuffer()); 3144 3145 CommandLineArgs* pCmdLine = GetCommandLineArgs(); 3146 if ( !pCmdLine->IsInvisible() && !pCmdLine->IsTerminateAfterInit() ) 3147 { 3148 ProcessDocumentsRequest* pDocsRequest = new ProcessDocumentsRequest( 3149 pCmdLine->getCwdUrl()); 3150 pDocsRequest->aOpenList = aOpenURL; 3151 pDocsRequest->pcProcessed = NULL; 3152 3153 OfficeIPCThread::ExecuteCmdLineRequests( *pDocsRequest ); 3154 delete pDocsRequest; 3155 } 3156 } 3157 else if ( rAppEvent.GetEvent() == APPEVENT_PRINT_STRING ) 3158 { 3159 OUString aPrintURL(rAppEvent.GetData().GetBuffer()); 3160 3161 CommandLineArgs* pCmdLine = GetCommandLineArgs(); 3162 if ( !pCmdLine->IsInvisible() && !pCmdLine->IsTerminateAfterInit() ) 3163 { 3164 ProcessDocumentsRequest* pDocsRequest = new ProcessDocumentsRequest( 3165 pCmdLine->getCwdUrl()); 3166 pDocsRequest->aPrintList = aPrintURL; 3167 pDocsRequest->pcProcessed = NULL; 3168 3169 OfficeIPCThread::ExecuteCmdLineRequests( *pDocsRequest ); 3170 delete pDocsRequest; 3171 } 3172 } 3173 #ifndef UNX 3174 else if ( rAppEvent.GetEvent() == "HELP" ) 3175 { 3176 // in non unix version allow showing of cmdline help window 3177 displayCmdlineHelp(); 3178 } 3179 #endif 3180 else if ( rAppEvent.GetEvent() == "SHOWDIALOG" ) 3181 { 3182 // ignore all errors here. It's clicking a menu entry only ... 3183 // The user will try it again, in case nothing happens .-) 3184 try 3185 { 3186 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); 3187 3188 com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider > 3189 xDesktop( xSMGR->createInstance( OUSTRING(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ), 3190 ::com::sun::star::uno::UNO_QUERY ); 3191 3192 // check provider ... we know it's weak reference only 3193 if ( ! xDesktop.is()) 3194 return; 3195 3196 css::uno::Reference< css::util::XURLTransformer > xParser(xSMGR->createInstance(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), css::uno::UNO_QUERY_THROW); 3197 css::util::URL aCommand; 3198 if( rAppEvent.GetData().EqualsAscii( "PREFERENCES" ) ) 3199 aCommand.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:OptionsTreeDialog" ) ); 3200 else if( rAppEvent.GetData().EqualsAscii( "ABOUT" ) ) 3201 aCommand.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:About" ) ); 3202 if( aCommand.Complete.getLength() ) 3203 { 3204 xParser->parseStrict(aCommand); 3205 3206 css::uno::Reference< css::frame::XDispatch > xDispatch = xDesktop->queryDispatch(aCommand, rtl::OUString(), 0); 3207 if (xDispatch.is()) 3208 xDispatch->dispatch(aCommand, css::uno::Sequence< css::beans::PropertyValue >()); 3209 } 3210 } 3211 catch(const css::uno::Exception&) 3212 {} 3213 } 3214 else if( rAppEvent.GetEvent() == "PRIVATE:DOSHUTDOWN" ) 3215 { 3216 Desktop* pD = dynamic_cast<Desktop*>(GetpApp()); 3217 OSL_ENSURE( pD, "no desktop ?!?" ); 3218 if( pD ) 3219 pD->doShutdown(); 3220 } 3221 } 3222 3223 void Desktop::OpenSplashScreen() 3224 { 3225 ::rtl::OUString aTmpString; 3226 CommandLineArgs* pCmdLine = GetCommandLineArgs(); 3227 sal_Bool bVisible = sal_False; 3228 // Show intro only if this is normal start (e.g. no server, no quickstart, no printing ) 3229 if ( !pCmdLine->IsInvisible() && 3230 !pCmdLine->IsHeadless() && 3231 !pCmdLine->IsQuickstart() && 3232 !pCmdLine->IsMinimized() && 3233 !pCmdLine->IsNoLogo() && 3234 !pCmdLine->IsTerminateAfterInit() && 3235 !pCmdLine->GetPrintList( aTmpString ) && 3236 !pCmdLine->GetPrintToList( aTmpString ) ) 3237 { 3238 // Determine application name from command line parameters 3239 OUString aAppName; 3240 if ( pCmdLine->IsWriter() ) 3241 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "writer" )); 3242 else if ( pCmdLine->IsCalc() ) 3243 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "calc" )); 3244 else if ( pCmdLine->IsDraw() ) 3245 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "draw" )); 3246 else if ( pCmdLine->IsImpress() ) 3247 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "impress" )); 3248 else if ( pCmdLine->IsBase() ) 3249 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "base" )); 3250 else if ( pCmdLine->IsGlobal() ) 3251 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "global" )); 3252 else if ( pCmdLine->IsMath() ) 3253 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "math" )); 3254 else if ( pCmdLine->IsWeb() ) 3255 aAppName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "web" )); 3256 3257 bVisible = sal_True; 3258 Sequence< Any > aSeq( 2 ); 3259 aSeq[0] <<= bVisible; 3260 aSeq[1] <<= aAppName; 3261 m_rSplashScreen = Reference<XStatusIndicator>( 3262 comphelper::getProcessServiceFactory()->createInstanceWithArguments( 3263 OUString::createFromAscii("com.sun.star.office.SplashScreen"), 3264 aSeq), UNO_QUERY); 3265 3266 if(m_rSplashScreen.is()) 3267 m_rSplashScreen->start(OUString::createFromAscii("SplashScreen"), 100); 3268 } 3269 3270 } 3271 3272 void Desktop::SetSplashScreenProgress(sal_Int32 iProgress) 3273 { 3274 if(m_rSplashScreen.is()) 3275 { 3276 m_rSplashScreen->setValue(iProgress); 3277 } 3278 } 3279 3280 void Desktop::SetSplashScreenText( const ::rtl::OUString& rText ) 3281 { 3282 if( m_rSplashScreen.is() ) 3283 { 3284 m_rSplashScreen->setText( rText ); 3285 } 3286 } 3287 3288 void Desktop::CloseSplashScreen() 3289 { 3290 if(m_rSplashScreen.is()) 3291 { 3292 m_rSplashScreen->end(); 3293 m_rSplashScreen = NULL; 3294 } 3295 } 3296 3297 // ======================================================================== 3298 void Desktop::DoFirstRunInitializations() 3299 { 3300 try 3301 { 3302 Reference< XJobExecutor > xExecutor( ::comphelper::getProcessServiceFactory()->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.task.JobExecutor" ) ), UNO_QUERY ); 3303 if( xExecutor.is() ) 3304 xExecutor->trigger( ::rtl::OUString::createFromAscii("onFirstRunInitialization") ); 3305 } 3306 catch(const ::com::sun::star::uno::Exception&) 3307 { 3308 OSL_ENSURE( sal_False, "Desktop::DoFirstRunInitializations: caught an exception while trigger job executor ..." ); 3309 } 3310 } 3311 3312 // ======================================================================== 3313 void Desktop::CheckFirstRun( ) 3314 { 3315 const ::rtl::OUString sCommonMiscNodeName = ::rtl::OUString::createFromAscii( "/org.openoffice.Office.Common/Misc" ); 3316 const ::rtl::OUString sFirstRunNodeName = ::rtl::OUString::createFromAscii( "FirstRun" ); 3317 3318 // -------------------------------------------------------------------- 3319 // check if this is the first office start 3320 3321 // for this, open the Common/Misc node where this info is stored 3322 ::utl::OConfigurationTreeRoot aCommonMisc = ::utl::OConfigurationTreeRoot::createWithServiceFactory( 3323 ::comphelper::getProcessServiceFactory( ), 3324 sCommonMiscNodeName, 3325 2, 3326 ::utl::OConfigurationTreeRoot::CM_UPDATABLE 3327 ); 3328 3329 // read the flag 3330 OSL_ENSURE( aCommonMisc.isValid(), "Desktop::CheckFirstRun: could not open the config node needed!" ); 3331 sal_Bool bIsFirstRun = sal_False; 3332 aCommonMisc.getNodeValue( sFirstRunNodeName ) >>= bIsFirstRun; 3333 3334 if ( !bIsFirstRun ) 3335 // nothing to do .... 3336 return; 3337 3338 // -------------------------------------------------------------------- 3339 // it is the first run 3340 // this has once been done using a vos timer. this could lead to problems when 3341 // the timer would trigger when the app is already going down again, since VCL would 3342 // no longer be available. Since the old handler would do a postUserEvent to the main 3343 // thread anyway, we can use a vcl timer here to prevent the race contition (#107197#) 3344 m_firstRunTimer.SetTimeout(3000); // 3 sec. 3345 m_firstRunTimer.SetTimeoutHdl(LINK(this, Desktop, AsyncInitFirstRun)); 3346 m_firstRunTimer.Start(); 3347 3348 // -------------------------------------------------------------------- 3349 // reset the config flag 3350 3351 // set the value 3352 aCommonMisc.setNodeValue( sFirstRunNodeName, makeAny( (sal_Bool)sal_False ) ); 3353 // commit the changes 3354 aCommonMisc.commit(); 3355 } 3356 3357 } 3358