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