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