Branch data 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 : :
21 : : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
22 : : #include <com/sun/star/awt/XRequestCallback.hpp>
23 : : #include <com/sun/star/frame/XDesktop.hpp>
24 : : #include <com/sun/star/beans/XPropertySet.hpp>
25 : :
26 : : #include <comphelper_module.hxx>
27 : : #include "officerestartmanager.hxx"
28 : :
29 : : using namespace ::com::sun::star;
30 : :
31 : : namespace comphelper
32 : : {
33 : :
34 : : // ----------------------------------------------------------
35 : 454 : uno::Sequence< ::rtl::OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames_static()
36 : : {
37 : 454 : uno::Sequence< rtl::OUString > aResult( 1 );
38 [ + - ][ + - ]: 454 : aResult[0] = getServiceName_static();
39 : 454 : return aResult;
40 : : }
41 : :
42 : : // ----------------------------------------------------------
43 : 454 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getImplementationName_static()
44 : : {
45 : 454 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.task.OfficeRestartManager" ) );
46 : : }
47 : :
48 : : // ----------------------------------------------------------
49 : 227 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getSingletonName_static()
50 : : {
51 : 227 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.OfficeRestartManager" ) );
52 : : }
53 : :
54 : : // ----------------------------------------------------------
55 : 454 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getServiceName_static()
56 : : {
57 : 454 : return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.task.OfficeRestartManager" ) );
58 : : }
59 : :
60 : : // ----------------------------------------------------------
61 : 158 : uno::Reference< uno::XInterface > SAL_CALL OOfficeRestartManager::Create( const uno::Reference< uno::XComponentContext >& rxContext )
62 : : {
63 [ + - ]: 158 : return static_cast< cppu::OWeakObject* >( new OOfficeRestartManager( rxContext ) );
64 : : }
65 : :
66 : : // XRestartManager
67 : : // ----------------------------------------------------------
68 : 62 : void SAL_CALL OOfficeRestartManager::requestRestart( const uno::Reference< task::XInteractionHandler >& /* xInteractionHandler */ )
69 : : throw (uno::Exception, uno::RuntimeException)
70 : : {
71 [ - + ]: 62 : if ( !m_xContext.is() )
72 [ # # ]: 0 : throw uno::RuntimeException();
73 : :
74 : : {
75 [ + - ]: 62 : ::osl::MutexGuard aGuard( m_aMutex );
76 : :
77 : : // if the restart already running there is no need to trigger it again
78 [ - + ]: 62 : if ( m_bRestartRequested )
79 : : return;
80 : :
81 : 62 : m_bRestartRequested = sal_True;
82 : :
83 : : // the office is still not initialized, no need to terminate, changing the state is enough
84 [ + - ]: 62 : if ( !m_bOfficeInitialized )
85 [ + - ][ - + ]: 62 : return;
86 : : }
87 : :
88 : : // TODO: use InteractionHandler to report errors
89 : : try
90 : : {
91 : : // register itself as a job that should be executed asynchronously
92 [ # # ][ # # ]: 62 : uno::Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager(), uno::UNO_SET_THROW );
[ # # ]
93 : :
94 : : uno::Reference< awt::XRequestCallback > xRequestCallback(
95 [ # # ]: 0 : xFactory->createInstanceWithContext(
96 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.AsyncCallback" )),
97 : 0 : m_xContext ),
98 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
99 : :
100 [ # # ][ # # ]: 62 : xRequestCallback->addCallback( this, uno::Any() );
[ # # ][ # # ]
101 : : }
102 : 0 : catch ( uno::Exception& )
103 : : {
104 : : // the try to request restart has failed
105 : 0 : m_bRestartRequested = sal_False;
106 : : }
107 : : }
108 : :
109 : : // ----------------------------------------------------------
110 : 412 : ::sal_Bool SAL_CALL OOfficeRestartManager::isRestartRequested( ::sal_Bool bOfficeInitialized )
111 : : throw (uno::Exception, uno::RuntimeException)
112 : : {
113 [ + - ]: 412 : ::osl::MutexGuard aGuard( m_aMutex );
114 : :
115 [ + - ][ + + ]: 412 : if ( bOfficeInitialized && !m_bOfficeInitialized )
116 : 158 : m_bOfficeInitialized = bOfficeInitialized;
117 : :
118 [ + - ]: 412 : return m_bRestartRequested;
119 : : }
120 : :
121 : : // XCallback
122 : : // ----------------------------------------------------------
123 : 0 : void SAL_CALL OOfficeRestartManager::notify( const uno::Any& /* aData */ )
124 : : throw ( uno::RuntimeException )
125 : : {
126 : : try
127 : : {
128 : 0 : sal_Bool bSuccess = sal_False;
129 : :
130 [ # # ]: 0 : if ( m_xContext.is() )
131 : : {
132 [ # # ][ # # ]: 0 : uno::Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager(), uno::UNO_SET_THROW );
[ # # ]
133 : : uno::Reference< frame::XDesktop > xDesktop(
134 [ # # ]: 0 : xFactory->createInstanceWithContext(
135 : 0 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ), m_xContext ),
136 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
137 : :
138 : : // Turn Quickstarter veto off
139 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xPropertySet( xDesktop, uno::UNO_QUERY_THROW );
140 [ # # ]: 0 : ::rtl::OUString aVetoPropName( RTL_CONSTASCII_USTRINGPARAM( "SuspendQuickstartVeto" ) );
141 : 0 : uno::Any aValue;
142 [ # # # # ]: 0 : aValue <<= (sal_Bool)sal_True;
143 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( aVetoPropName, aValue );
144 : :
145 : : try
146 : : {
147 [ # # ][ # # ]: 0 : bSuccess = xDesktop->terminate();
148 [ # # ]: 0 : } catch( uno::Exception& )
149 : : {}
150 : :
151 [ # # ]: 0 : if ( !bSuccess )
152 : : {
153 [ # # ]: 0 : aValue <<= (sal_Bool)sal_False;
154 [ # # ][ # # ]: 0 : xPropertySet->setPropertyValue( aVetoPropName, aValue );
155 [ # # ]: 0 : }
156 : : }
157 : :
158 [ # # ]: 0 : if ( !bSuccess )
159 : 0 : m_bRestartRequested = sal_False;
160 : : }
161 : 0 : catch( uno::Exception& )
162 : : {
163 : : // the try to restart has failed
164 : 0 : m_bRestartRequested = sal_False;
165 : : }
166 : 0 : }
167 : :
168 : : // XServiceInfo
169 : : // ----------------------------------------------------------
170 : 0 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getImplementationName() throw (uno::RuntimeException)
171 : : {
172 : 0 : return getImplementationName_static();
173 : : }
174 : :
175 : : // ----------------------------------------------------------
176 : 0 : ::sal_Bool SAL_CALL OOfficeRestartManager::supportsService( const ::rtl::OUString& aServiceName ) throw (uno::RuntimeException)
177 : : {
178 : 0 : const uno::Sequence< rtl::OUString > & aSupportedNames = getSupportedServiceNames_static();
179 [ # # ]: 0 : for ( sal_Int32 nInd = 0; nInd < aSupportedNames.getLength(); nInd++ )
180 : : {
181 [ # # ]: 0 : if ( aSupportedNames[ nInd ].equals( aServiceName ) )
182 : 0 : return sal_True;
183 : : }
184 : :
185 : 0 : return sal_False;
186 : : }
187 : :
188 : : // ----------------------------------------------------------
189 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames() throw (uno::RuntimeException)
190 : : {
191 : 0 : return getSupportedServiceNames_static();
192 : : }
193 : :
194 : : } // namespace comphelper
195 : :
196 : 227 : void createRegistryInfo_OOfficeRestartManager()
197 : : {
198 [ + - ][ + - ]: 227 : static ::comphelper::module::OAutoRegistration< ::comphelper::OOfficeRestartManager > aAutoRegistration;
[ + - ][ # # ]
199 [ + - ][ + - ]: 227 : static ::comphelper::module::OSingletonRegistration< ::comphelper::OOfficeRestartManager > aSingletonRegistration;
[ + - ][ # # ]
200 : 227 : }
201 : :
202 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|