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