Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <osl/file.hxx>
21 : #include <rtl/bootstrap.hxx>
22 : #include <rtl/ustring.hxx>
23 : #include <unotools/configmgr.hxx>
24 :
25 : #include <comphelper/processfactory.hxx>
26 : #include <com/sun/star/beans/XPropertySet.hpp>
27 : #include <com/sun/star/beans/NamedValue.hpp>
28 : #include <com/sun/star/configuration/theDefaultProvider.hpp>
29 : #include <com/sun/star/util/XChangesBatch.hpp>
30 :
31 : #include "app.hxx"
32 :
33 : using ::rtl::OUString;
34 : using namespace ::desktop;
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::beans;
37 :
38 : static const char aAccessSrvc[] = "com.sun.star.configuration.ConfigurationUpdateAccess";
39 :
40 : /* Local function - get access to the configuration */
41 0 : static Reference< XPropertySet > impl_getConfigurationAccess( const OUString& rPath )
42 : {
43 : Reference< XMultiServiceFactory > xConfigProvider(
44 : configuration::theDefaultProvider::get(
45 0 : comphelper::getProcessComponentContext() ) );
46 0 : Sequence< Any > aArgs( 1 );
47 0 : NamedValue aValue( OUString( "nodepath" ), makeAny( rPath ) );
48 0 : aArgs[0] <<= aValue;
49 : return Reference< XPropertySet >(
50 0 : xConfigProvider->createInstanceWithArguments( rtl::OUString(aAccessSrvc), aArgs ), UNO_QUERY_THROW );
51 : }
52 :
53 0 : void Desktop::DoRestartActionsIfNecessary( sal_Bool bQuickStart )
54 : {
55 0 : if ( bQuickStart )
56 : {
57 : try
58 : {
59 0 : Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( "org.openoffice.Setup/Office" ) );
60 :
61 0 : OUString sPropName( "OfficeRestartInProgress" );
62 0 : Any aRestart = xPSet->getPropertyValue( sPropName );
63 0 : sal_Bool bRestart = sal_False;
64 0 : if ( ( aRestart >>= bRestart ) && bRestart )
65 : {
66 0 : xPSet->setPropertyValue( sPropName, makeAny( sal_False ) );
67 0 : Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges();
68 :
69 0 : Sequence< Any > aSeq( 1 );
70 0 : sal_Bool bQuickstart = shouldLaunchQuickstart();
71 0 : aSeq[0] <<= bQuickstart;
72 :
73 0 : Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance(
74 0 : OUString( "com.sun.star.office.Quickstart" ) ),UNO_QUERY_THROW );
75 0 : xQuickstart->initialize( aSeq );
76 0 : }
77 : }
78 0 : catch( const uno::Exception& )
79 : {
80 : // this is no critical operation so it should not prevent office from starting
81 : }
82 : }
83 0 : }
84 :
85 0 : void Desktop::SetRestartState()
86 : {
87 : try
88 : {
89 0 : Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( "org.openoffice.Setup/Office" ) );
90 0 : OUString sPropName( "OfficeRestartInProgress" );
91 0 : xPSet->setPropertyValue( sPropName, makeAny( sal_True ) );
92 0 : Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges();
93 : }
94 0 : catch( const uno::Exception& )
95 : {
96 : // this is no critical operation, ignore the exception
97 : }
98 :
99 0 : }
100 :
101 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|