LibreOffice Module desktop (master) 1
dp_commandenvironments.cxx
Go to the documentation of this file.
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/XInteractionHandler.hpp>
28#include <com/sun/star/ucb/XCommandEnvironment.hpp>
29#include <utility>
31#include <osl/diagnose.h>
32
34namespace task = com::sun::star::task;
35namespace ucb = com::sun::star::ucb;
36namespace uno = com::sun::star::uno;
37
38using ::com::sun::star::uno::Reference;
39
40namespace dp_manager {
41
43{
44}
45
47 Reference< task::XInteractionHandler> const & handler)
48 : m_forwardHandler(handler)
49{
50}
51
53{
54}
55// XCommandEnvironment
56
57Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
58{
59 return this;
60}
61
62
63Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
64{
65 return this;
66}
67
69 Reference< task::XInteractionRequest> const & /*xRequest*/ )
70{
71}
72
73void BaseCommandEnv::handle_(bool approve,
74 Reference< task::XInteractionRequest> const & xRequest )
75{
76 if (!approve)
77 {
78 //not handled so far -> forwarding
79 if (m_forwardHandler.is())
80 m_forwardHandler->handle(xRequest);
81 else
82 return; //cannot handle
83 }
84 else
85 {
86 // select:
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 )
93 {
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;
101 }
102 }
103 }
104 }
105
106}
107
108// XProgressHandler
109void BaseCommandEnv::push( uno::Any const & /*Status*/ )
110{
111}
112
113void BaseCommandEnv::update( uno::Any const & /*Status */)
114{
115}
116
118{
119}
120
121
123{
124}
125
127 css::uno::Reference< css::task::XInteractionHandler> const & handler):
128 BaseCommandEnv(handler)
129{
130}
131// XInteractionHandler
133 Reference< task::XInteractionRequest> const & xRequest )
134{
135 uno::Any request( xRequest->getRequest() );
136 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
137
138 deployment::VersionException verExc;
139 deployment::LicenseException licExc;
140 deployment::InstallException instExc;
141
142 bool approve = false;
143
144 if ((request >>= verExc)
145 || (request >>= licExc)
146 || (request >>= instExc))
147 {
148 approve = true;
149 }
150
151 handle_(approve, xRequest);
152}
153
154
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)
161{
162}
163// XInteractionHandler
165 Reference< task::XInteractionRequest> const & xRequest )
166{
167 uno::Any request( xRequest->getRequest() );
168 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
169
170 deployment::LicenseException licExc;
171
172 bool approve = false;
173
174 if (request >>= licExc)
175 {
177 || m_repository == "bundled"
178 || licExc.AcceptBy == "admin")
179 {
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;
185 }
186 }
187
188 handle_(approve, xRequest);
189}
190
191
193 css::uno::Reference< css::task::XInteractionHandler> const & handler):
194 BaseCommandEnv(handler)
195{
196}
197// XInteractionHandler
199 Reference< task::XInteractionRequest> const & xRequest )
200{
201 uno::Any request( xRequest->getRequest() );
202 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
203
204 deployment::LicenseException licExc;
205
206 bool approve = false;
207
208 if (request >>= licExc)
209 {
210 approve = true;
211 }
212 handle_(approve, xRequest);
213}
214
216{
217}
218
220 Reference< task::XInteractionRequest> const & xRequest )
221{
222 uno::Any request( xRequest->getRequest() );
223 OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
224
225 deployment::LicenseException licExc;
226 deployment::PlatformException platformExc;
227 deployment::DependencyException depExc;
228
229 if (request >>= licExc)
230 {
231 handle_(true, xRequest); // approve = true
232 }
233 else if ((request >>= platformExc)
234 || (request >>= depExc))
235 {
236 m_Exception = request;
237 }
238 else
239 {
240 m_UnknownException = request;
241 }
242}
243
244}
245
246/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This command environment is to be used when an extension is temporarily stored in the "tmp" repositor...
void handle_(bool approve, css::uno::Reference< css::task::XInteractionRequest > const &xRequest)
virtual css::uno::Reference< css::task::XInteractionHandler > SAL_CALL getInteractionHandler() override
css::uno::Reference< css::task::XInteractionHandler > m_forwardHandler
virtual void SAL_CALL pop() override
virtual void SAL_CALL push(css::uno::Any const &Status) override
virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL getProgressHandler() override
virtual void SAL_CALL update(css::uno::Any const &Status) override
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
LicenseCommandEnv(css::uno::Reference< css::task::XInteractionHandler > const &handler, bool bSuppressLicense, OUString repository)
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
NoLicenseCommandEnv(css::uno::Reference< css::task::XInteractionHandler > const &handler)
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
virtual void SAL_CALL handle(css::uno::Reference< css::task::XInteractionRequest > const &xRequest) override
size_t pos