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/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 :
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;
37 :
38 : using ::com::sun::star::uno::Reference;
39 :
40 : namespace dp_manager {
41 :
42 2 : BaseCommandEnv::BaseCommandEnv()
43 : {
44 2 : }
45 :
46 1 : BaseCommandEnv::BaseCommandEnv(
47 : Reference< task::XInteractionHandler> const & handler)
48 1 : : m_forwardHandler(handler)
49 : {
50 1 : }
51 :
52 3 : BaseCommandEnv::~BaseCommandEnv()
53 : {
54 3 : }
55 : // XCommandEnvironment
56 :
57 3 : Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
58 : throw (uno::RuntimeException, std::exception)
59 : {
60 3 : return this;
61 : }
62 :
63 :
64 5 : Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
65 : throw (uno::RuntimeException, std::exception)
66 : {
67 5 : return this;
68 : }
69 :
70 0 : void BaseCommandEnv::handle(
71 : Reference< task::XInteractionRequest> const & /*xRequest*/ )
72 : throw (uno::RuntimeException, std::exception)
73 : {
74 0 : }
75 :
76 0 : void BaseCommandEnv::handle_(bool approve, bool abort,
77 : Reference< task::XInteractionRequest> const & xRequest )
78 : {
79 0 : if (!approve && !abort)
80 : {
81 : //not handled so far -> forwarding
82 0 : if (m_forwardHandler.is())
83 0 : m_forwardHandler->handle(xRequest);
84 : else
85 0 : return; //cannot handle
86 : }
87 : else
88 : {
89 : // select:
90 : uno::Sequence< Reference< task::XInteractionContinuation > > conts(
91 0 : xRequest->getContinuations() );
92 : Reference< task::XInteractionContinuation > const * pConts =
93 0 : conts.getConstArray();
94 0 : sal_Int32 len = conts.getLength();
95 0 : for ( sal_Int32 pos = 0; pos < len; ++pos )
96 : {
97 0 : if (approve) {
98 : Reference< task::XInteractionApprove > xInteractionApprove(
99 0 : pConts[ pos ], uno::UNO_QUERY );
100 0 : if (xInteractionApprove.is()) {
101 0 : xInteractionApprove->select();
102 : // don't query again for ongoing continuations:
103 0 : approve = false;
104 0 : }
105 : }
106 0 : else if (abort) {
107 : Reference< task::XInteractionAbort > xInteractionAbort(
108 0 : pConts[ pos ], uno::UNO_QUERY );
109 0 : if (xInteractionAbort.is()) {
110 0 : xInteractionAbort->select();
111 : // don't query again for ongoing continuations:
112 0 : abort = false;
113 0 : }
114 : }
115 0 : }
116 : }
117 :
118 : }
119 :
120 : // XProgressHandler
121 0 : void BaseCommandEnv::push( uno::Any const & /*Status*/ )
122 : throw (uno::RuntimeException, std::exception)
123 : {
124 0 : }
125 :
126 2 : void BaseCommandEnv::update( uno::Any const & /*Status */)
127 : throw (uno::RuntimeException, std::exception)
128 : {
129 2 : }
130 :
131 0 : void BaseCommandEnv::pop() throw (uno::RuntimeException, std::exception)
132 : {
133 0 : }
134 :
135 :
136 1 : TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
137 : {
138 1 : }
139 :
140 1 : TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
141 : css::uno::Reference< css::task::XInteractionHandler> const & handler):
142 1 : BaseCommandEnv(handler)
143 : {
144 1 : }
145 : // XInteractionHandler
146 0 : void TmpRepositoryCommandEnv::handle(
147 : Reference< task::XInteractionRequest> const & xRequest )
148 : throw (uno::RuntimeException, std::exception)
149 : {
150 0 : uno::Any request( xRequest->getRequest() );
151 : OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
152 :
153 0 : deployment::VersionException verExc;
154 0 : deployment::LicenseException licExc;
155 0 : deployment::InstallException instExc;
156 :
157 0 : bool approve = false;
158 0 : bool abort = false;
159 :
160 0 : if ((request >>= verExc)
161 0 : || (request >>= licExc)
162 0 : || (request >>= instExc))
163 : {
164 0 : approve = true;
165 : }
166 :
167 0 : handle_(approve, abort, xRequest);
168 0 : }
169 :
170 :
171 0 : LicenseCommandEnv::LicenseCommandEnv(
172 : css::uno::Reference< css::task::XInteractionHandler> const & handler,
173 : bool bSuppressLicense,
174 : OUString const & repository):
175 : BaseCommandEnv(handler), m_repository(repository),
176 0 : m_bSuppressLicense(bSuppressLicense)
177 : {
178 0 : }
179 : // XInteractionHandler
180 0 : void LicenseCommandEnv::handle(
181 : Reference< task::XInteractionRequest> const & xRequest )
182 : throw (uno::RuntimeException, std::exception)
183 : {
184 0 : uno::Any request( xRequest->getRequest() );
185 : OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
186 :
187 0 : deployment::LicenseException licExc;
188 :
189 0 : bool approve = false;
190 0 : bool abort = false;
191 :
192 0 : if (request >>= licExc)
193 : {
194 0 : if (m_bSuppressLicense
195 0 : || m_repository == "bundled"
196 0 : || licExc.AcceptBy == "admin")
197 : {
198 : //always approve in bundled case, because we do not support
199 : //showing licenses anyway.
200 : //The "admin" already accepted the license when installing the
201 : // shared extension
202 0 : approve = true;
203 : }
204 : }
205 :
206 0 : handle_(approve, abort, xRequest);
207 0 : }
208 :
209 :
210 :
211 0 : NoLicenseCommandEnv::NoLicenseCommandEnv(
212 : css::uno::Reference< css::task::XInteractionHandler> const & handler):
213 0 : BaseCommandEnv(handler)
214 : {
215 0 : }
216 : // XInteractionHandler
217 0 : void NoLicenseCommandEnv::handle(
218 : Reference< task::XInteractionRequest> const & xRequest )
219 : throw (uno::RuntimeException, std::exception)
220 : {
221 0 : uno::Any request( xRequest->getRequest() );
222 : OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
223 :
224 0 : deployment::LicenseException licExc;
225 :
226 0 : bool approve = false;
227 0 : bool abort = false;
228 :
229 0 : if (request >>= licExc)
230 : {
231 0 : approve = true;
232 : }
233 0 : handle_(approve, abort, xRequest);
234 0 : }
235 :
236 1 : SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
237 : {
238 1 : }
239 :
240 0 : void SilentCheckPrerequisitesCommandEnv::handle(
241 : Reference< task::XInteractionRequest> const & xRequest )
242 : throw (uno::RuntimeException, std::exception)
243 : {
244 0 : uno::Any request( xRequest->getRequest() );
245 : OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
246 :
247 0 : deployment::LicenseException licExc;
248 0 : deployment::PlatformException platformExc;
249 0 : deployment::DependencyException depExc;
250 :
251 0 : if (request >>= licExc)
252 : {
253 0 : handle_(true, false, xRequest); // approve = true, abort = false
254 : }
255 0 : else if ((request >>= platformExc)
256 0 : || (request >>= depExc))
257 : {
258 0 : m_Exception = request;
259 : }
260 : else
261 : {
262 0 : m_UnknownException = request;
263 0 : }
264 0 : }
265 :
266 : }
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|