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 : #include <com/sun/star/office/Quickstart.hpp>
31 :
32 : #include "app.hxx"
33 :
34 : using namespace ::desktop;
35 : using namespace ::com::sun::star;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::lang;
38 : using namespace ::com::sun::star::uno;
39 :
40 : static const char aAccessSrvc[] = "com.sun.star.configuration.ConfigurationUpdateAccess";
41 :
42 : /* Local function - get access to the configuration */
43 32 : static Reference< XPropertySet > impl_getConfigurationAccess( const OUString& rPath )
44 : {
45 : Reference< XMultiServiceFactory > xConfigProvider(
46 : configuration::theDefaultProvider::get(
47 32 : comphelper::getProcessComponentContext() ) );
48 64 : Sequence< Any > aArgs( 1 );
49 64 : NamedValue aValue( OUString( "nodepath" ), makeAny( rPath ) );
50 32 : aArgs[0] <<= aValue;
51 : return Reference< XPropertySet >(
52 64 : xConfigProvider->createInstanceWithArguments( OUString(aAccessSrvc), aArgs ), UNO_QUERY_THROW );
53 : }
54 :
55 51 : void Desktop::DoRestartActionsIfNecessary( sal_Bool bQuickStart )
56 : {
57 51 : if ( bQuickStart )
58 : {
59 : try
60 : {
61 0 : Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( "org.openoffice.Setup/Office" ) );
62 :
63 0 : OUString sPropName( "OfficeRestartInProgress" );
64 0 : Any aRestart = xPSet->getPropertyValue( sPropName );
65 0 : sal_Bool bRestart = sal_False;
66 0 : if ( ( aRestart >>= bRestart ) && bRestart )
67 : {
68 0 : xPSet->setPropertyValue( sPropName, makeAny( sal_False ) );
69 0 : Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges();
70 :
71 0 : sal_Bool bQuickstart = shouldLaunchQuickstart();
72 :
73 0 : css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
74 0 : css::office::Quickstart::createStart(xContext, bQuickstart);
75 0 : }
76 : }
77 0 : catch( const uno::Exception& )
78 : {
79 : // this is no critical operation so it should not prevent office from starting
80 : }
81 : }
82 51 : }
83 :
84 32 : void Desktop::SetRestartState()
85 : {
86 : try
87 : {
88 32 : Reference< XPropertySet > xPSet = impl_getConfigurationAccess( OUString( "org.openoffice.Setup/Office" ) );
89 64 : OUString sPropName( "OfficeRestartInProgress" );
90 32 : xPSet->setPropertyValue( sPropName, makeAny( sal_True ) );
91 64 : Reference< util::XChangesBatch >( xPSet, UNO_QUERY_THROW )->commitChanges();
92 : }
93 0 : catch( const uno::Exception& )
94 : {
95 : // this is no critical operation, ignore the exception
96 : }
97 :
98 281 : }
99 :
100 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|