Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / desktop / source / deployment / manager / dp_commandenvironments.cxx
blob1ac6ae7ecb922d7d702474f0262a56a536389867
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/deployment/VersionException.hpp>
22 #include <com/sun/star/deployment/LicenseException.hpp>
23 #include <com/sun/star/deployment/InstallException.hpp>
24 #include <com/sun/star/deployment/DependencyException.hpp>
25 #include <com/sun/star/deployment/PlatformException.hpp>
26 #include <com/sun/star/task/XInteractionApprove.hpp>
27 #include <com/sun/star/task/XInteractionAbort.hpp>
28 #include <com/sun/star/task/XInteractionHandler.hpp>
29 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include "dp_commandenvironments.hxx"
32 #include <osl/diagnose.h>
34 namespace deployment = com::sun::star::deployment;
35 namespace task = com::sun::star::task;
36 namespace ucb = com::sun::star::ucb;
37 namespace uno = com::sun::star::uno;
39 using ::com::sun::star::uno::Reference;
41 namespace dp_manager {
43 BaseCommandEnv::BaseCommandEnv()
47 BaseCommandEnv::BaseCommandEnv(
48 Reference< task::XInteractionHandler> const & handler)
49 : m_forwardHandler(handler)
53 BaseCommandEnv::~BaseCommandEnv()
56 // XCommandEnvironment
58 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
60 return this;
64 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
66 return this;
69 void BaseCommandEnv::handle(
70 Reference< task::XInteractionRequest> const & /*xRequest*/ )
74 void BaseCommandEnv::handle_(bool approve,
75 Reference< task::XInteractionRequest> const & xRequest )
77 if (!approve)
79 //not handled so far -> forwarding
80 if (m_forwardHandler.is())
81 m_forwardHandler->handle(xRequest);
82 else
83 return; //cannot handle
85 else
87 // select:
88 uno::Sequence< Reference< task::XInteractionContinuation > > conts(
89 xRequest->getContinuations() );
90 Reference< task::XInteractionContinuation > const * pConts =
91 conts.getConstArray();
92 sal_Int32 len = conts.getLength();
93 for ( sal_Int32 pos = 0; pos < len; ++pos )
95 if (approve) {
96 Reference< task::XInteractionApprove > xInteractionApprove(
97 pConts[ pos ], uno::UNO_QUERY );
98 if (xInteractionApprove.is()) {
99 xInteractionApprove->select();
100 // don't query again for ongoing continuations:
101 approve = false;
109 // XProgressHandler
110 void BaseCommandEnv::push( uno::Any const & /*Status*/ )
114 void BaseCommandEnv::update( uno::Any const & /*Status */)
118 void BaseCommandEnv::pop()
123 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
127 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
128 css::uno::Reference< css::task::XInteractionHandler> const & handler):
129 BaseCommandEnv(handler)
132 // XInteractionHandler
133 void TmpRepositoryCommandEnv::handle(
134 Reference< task::XInteractionRequest> const & xRequest )
136 uno::Any request( xRequest->getRequest() );
137 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
139 deployment::VersionException verExc;
140 deployment::LicenseException licExc;
141 deployment::InstallException instExc;
143 bool approve = false;
145 if ((request >>= verExc)
146 || (request >>= licExc)
147 || (request >>= instExc))
149 approve = true;
152 handle_(approve, xRequest);
156 LicenseCommandEnv::LicenseCommandEnv(
157 css::uno::Reference< css::task::XInteractionHandler> const & handler,
158 bool bSuppressLicense,
159 OUString const & repository):
160 BaseCommandEnv(handler), m_repository(repository),
161 m_bSuppressLicense(bSuppressLicense)
164 // XInteractionHandler
165 void LicenseCommandEnv::handle(
166 Reference< task::XInteractionRequest> const & xRequest )
168 uno::Any request( xRequest->getRequest() );
169 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
171 deployment::LicenseException licExc;
173 bool approve = false;
175 if (request >>= licExc)
177 if (m_bSuppressLicense
178 || m_repository == "bundled"
179 || licExc.AcceptBy == "admin")
181 //always approve in bundled case, because we do not support
182 //showing licenses anyway.
183 //The "admin" already accepted the license when installing the
184 // shared extension
185 approve = true;
189 handle_(approve, xRequest);
193 NoLicenseCommandEnv::NoLicenseCommandEnv(
194 css::uno::Reference< css::task::XInteractionHandler> const & handler):
195 BaseCommandEnv(handler)
198 // XInteractionHandler
199 void NoLicenseCommandEnv::handle(
200 Reference< task::XInteractionRequest> const & xRequest )
202 uno::Any request( xRequest->getRequest() );
203 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
205 deployment::LicenseException licExc;
207 bool approve = false;
209 if (request >>= licExc)
211 approve = true;
213 handle_(approve, xRequest);
216 SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
220 void SilentCheckPrerequisitesCommandEnv::handle(
221 Reference< task::XInteractionRequest> const & xRequest )
223 uno::Any request( xRequest->getRequest() );
224 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
226 deployment::LicenseException licExc;
227 deployment::PlatformException platformExc;
228 deployment::DependencyException depExc;
230 if (request >>= licExc)
232 handle_(true, xRequest); // approve = true
234 else if ((request >>= platformExc)
235 || (request >>= depExc))
237 m_Exception = request;
239 else
241 m_UnknownException = request;
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */