android: Update app-specific/MIME type icons
[LibreOffice.git] / comphelper / source / misc / officerestartmanager.cxx
blob86eb18f623c9039f9ffb6aa58c313f38aa21a95f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
31 namespace comphelper
34 // XRestartManager
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 )
46 return;
48 m_bRestartRequested = true;
50 // the office is still not initialized, no need to terminate, changing the state is enough
51 if ( !m_bOfficeInitialized )
52 return;
55 // TODO: use InteractionHandler to report errors
56 try
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",
64 m_xContext ),
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;
87 // XCallback
89 void SAL_CALL OOfficeRestartManager::notify( const uno::Any& /* aData */ )
91 try
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" );
102 uno::Any aValue;
103 aValue <<= true;
104 xPropertySet->setPropertyValue( aVetoPropName, aValue );
108 bSuccess = xDesktop->terminate();
109 } catch( uno::Exception& )
112 if ( !bSuccess )
114 aValue <<= false;
115 xPropertySet->setPropertyValue( aVetoPropName, aValue );
119 if ( !bSuccess )
120 m_bRestartRequested = false;
122 catch( uno::Exception& )
124 // the try to restart has failed
125 m_bRestartRequested = false;
129 // XServiceInfo
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: */