Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / desktop / source / deployment / manager / dp_commandenvironments.cxx
blob0a25e042f0e98124d737a8897013b4310e3ea8e5
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/XInteractionHandler.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
29 #include <utility>
30 #include "dp_commandenvironments.hxx"
31 #include <osl/diagnose.h>
33 namespace deployment = com::sun::star::deployment;
34 namespace task = com::sun::star::task;
35 namespace ucb = com::sun::star::ucb;
36 namespace uno = com::sun::star::uno;
38 using ::com::sun::star::uno::Reference;
40 namespace dp_manager {
42 BaseCommandEnv::BaseCommandEnv()
46 BaseCommandEnv::BaseCommandEnv(
47 Reference< task::XInteractionHandler> const & handler)
48 : m_forwardHandler(handler)
52 BaseCommandEnv::~BaseCommandEnv()
55 // XCommandEnvironment
57 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
59 return this;
63 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
65 return this;
68 void BaseCommandEnv::handle(
69 Reference< task::XInteractionRequest> const & /*xRequest*/ )
73 void BaseCommandEnv::handle_(bool approve,
74 Reference< task::XInteractionRequest> const & xRequest )
76 if (!approve)
78 //not handled so far -> forwarding
79 if (m_forwardHandler.is())
80 m_forwardHandler->handle(xRequest);
81 else
82 return; //cannot handle
84 else
86 // select:
87 uno::Sequence< Reference< task::XInteractionContinuation > > conts(
88 xRequest->getContinuations() );
89 Reference< task::XInteractionContinuation > const * pConts =
90 conts.getConstArray();
91 sal_Int32 len = conts.getLength();
92 for ( sal_Int32 pos = 0; pos < len; ++pos )
94 if (approve) {
95 Reference< task::XInteractionApprove > xInteractionApprove(
96 pConts[ pos ], uno::UNO_QUERY );
97 if (xInteractionApprove.is()) {
98 xInteractionApprove->select();
99 // don't query again for ongoing continuations:
100 approve = false;
108 // XProgressHandler
109 void BaseCommandEnv::push( uno::Any const & /*Status*/ )
113 void BaseCommandEnv::update( uno::Any const & /*Status */)
117 void BaseCommandEnv::pop()
122 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
126 TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
127 css::uno::Reference< css::task::XInteractionHandler> const & handler):
128 BaseCommandEnv(handler)
131 // XInteractionHandler
132 void TmpRepositoryCommandEnv::handle(
133 Reference< task::XInteractionRequest> const & xRequest )
135 uno::Any request( xRequest->getRequest() );
136 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
138 deployment::VersionException verExc;
139 deployment::LicenseException licExc;
140 deployment::InstallException instExc;
142 bool approve = false;
144 if ((request >>= verExc)
145 || (request >>= licExc)
146 || (request >>= instExc))
148 approve = true;
151 handle_(approve, xRequest);
155 LicenseCommandEnv::LicenseCommandEnv(
156 css::uno::Reference< css::task::XInteractionHandler> const & handler,
157 bool bSuppressLicense,
158 OUString repository):
159 BaseCommandEnv(handler), m_repository(std::move(repository)),
160 m_bSuppressLicense(bSuppressLicense)
163 // XInteractionHandler
164 void LicenseCommandEnv::handle(
165 Reference< task::XInteractionRequest> const & xRequest )
167 uno::Any request( xRequest->getRequest() );
168 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
170 deployment::LicenseException licExc;
172 bool approve = false;
174 if (request >>= licExc)
176 if (m_bSuppressLicense
177 || m_repository == "bundled"
178 || licExc.AcceptBy == "admin")
180 //always approve in bundled case, because we do not support
181 //showing licenses anyway.
182 //The "admin" already accepted the license when installing the
183 // shared extension
184 approve = true;
188 handle_(approve, xRequest);
192 NoLicenseCommandEnv::NoLicenseCommandEnv(
193 css::uno::Reference< css::task::XInteractionHandler> const & handler):
194 BaseCommandEnv(handler)
197 // XInteractionHandler
198 void NoLicenseCommandEnv::handle(
199 Reference< task::XInteractionRequest> const & xRequest )
201 uno::Any request( xRequest->getRequest() );
202 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
204 deployment::LicenseException licExc;
206 bool approve = false;
208 if (request >>= licExc)
210 approve = true;
212 handle_(approve, xRequest);
215 SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
219 void SilentCheckPrerequisitesCommandEnv::handle(
220 Reference< task::XInteractionRequest> const & xRequest )
222 uno::Any request( xRequest->getRequest() );
223 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
225 deployment::LicenseException licExc;
226 deployment::PlatformException platformExc;
227 deployment::DependencyException depExc;
229 if (request >>= licExc)
231 handle_(true, xRequest); // approve = true
233 else if ((request >>= platformExc)
234 || (request >>= depExc))
236 m_Exception = request;
238 else
240 m_UnknownException = request;
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */