1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
22 #include <com/sun/star/awt/XRequestCallback.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include "officerestartmanager.hxx"
29 using namespace ::com::sun::star
;
36 void SAL_CALL
OOfficeRestartManager::requestRestart( const uno::Reference
< task::XInteractionHandler
>& /* xInteractionHandler */ )
38 if ( !m_xContext
.is() )
39 throw uno::RuntimeException();
42 std::unique_lock
aGuard( m_aMutex
);
44 // if the restart already running there is no need to trigger it again
45 if ( m_bRestartRequested
)
48 m_bRestartRequested
= true;
50 // the office is still not initialized, no need to terminate, changing the state is enough
51 if ( !m_bOfficeInitialized
)
55 // TODO: use InteractionHandler to report errors
58 // register itself as a job that should be executed asynchronously
59 uno::Reference
< lang::XMultiComponentFactory
> xFactory( m_xContext
->getServiceManager(), uno::UNO_SET_THROW
);
61 uno::Reference
< awt::XRequestCallback
> xRequestCallback(
62 xFactory
->createInstanceWithContext(
63 "com.sun.star.awt.AsyncCallback",
65 uno::UNO_QUERY_THROW
);
67 xRequestCallback
->addCallback( this, uno::Any() );
69 catch ( uno::Exception
& )
71 // the try to request restart has failed
72 m_bRestartRequested
= false;
77 sal_Bool SAL_CALL
OOfficeRestartManager::isRestartRequested( sal_Bool bOfficeInitialized
)
79 std::unique_lock
aGuard( m_aMutex
);
81 if ( bOfficeInitialized
&& !m_bOfficeInitialized
)
82 m_bOfficeInitialized
= bOfficeInitialized
;
84 return m_bRestartRequested
;
89 void SAL_CALL
OOfficeRestartManager::notify( const uno::Any
& /* aData */ )
93 bool bSuccess
= false;
95 if ( m_xContext
.is() )
97 uno::Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create(m_xContext
);
99 // Turn Quickstarter veto off
100 uno::Reference
< beans::XPropertySet
> xPropertySet( xDesktop
, uno::UNO_QUERY_THROW
);
101 OUString
aVetoPropName( "SuspendQuickstartVeto" );
104 xPropertySet
->setPropertyValue( aVetoPropName
, aValue
);
108 bSuccess
= xDesktop
->terminate();
109 } catch( uno::Exception
& )
115 xPropertySet
->setPropertyValue( aVetoPropName
, aValue
);
120 m_bRestartRequested
= false;
122 catch( uno::Exception
& )
124 // the try to restart has failed
125 m_bRestartRequested
= false;
131 OUString SAL_CALL
OOfficeRestartManager::getImplementationName()
133 return "com.sun.star.comp.task.OfficeRestartManager";
136 sal_Bool SAL_CALL
OOfficeRestartManager::supportsService( const OUString
& aServiceName
)
138 return cppu::supportsService(this, aServiceName
);
141 uno::Sequence
< OUString
> SAL_CALL
OOfficeRestartManager::getSupportedServiceNames()
143 return { "com.sun.star.comp.task.OfficeRestartManager" };
146 } // namespace comphelper
149 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
150 com_sun_star_comp_task_OfficeRestartManager(
151 css::uno::XComponentContext
*context
,
152 css::uno::Sequence
<css::uno::Any
> const &)
154 return cppu::acquire(new comphelper::OOfficeRestartManager(context
));
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */