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/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>
32 #include <osl/diagnose.h>
33 
35 namespace task = com::sun::star::task;
36 namespace ucb = com::sun::star::ucb;
37 namespace uno = com::sun::star::uno;
38 
39 using ::com::sun::star::uno::Reference;
40 
41 namespace dp_manager {
42 
44 {
45 }
46 
48  Reference< task::XInteractionHandler> const & handler)
49  : m_forwardHandler(handler)
50 {
51 }
52 
54 {
55 }
56 // XCommandEnvironment
57 
58 Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
59 {
60  return this;
61 }
62 
63 
64 Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
65 {
66  return this;
67 }
68 
70  Reference< task::XInteractionRequest> const & /*xRequest*/ )
71 {
72 }
73 
74 void BaseCommandEnv::handle_(bool approve,
75  Reference< task::XInteractionRequest> const & xRequest )
76 {
77  if (!approve)
78  {
79  //not handled so far -> forwarding
80  if (m_forwardHandler.is())
81  m_forwardHandler->handle(xRequest);
82  else
83  return; //cannot handle
84  }
85  else
86  {
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 )
94  {
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;
102  }
103  }
104  }
105  }
106 
107 }
108 
109 // XProgressHandler
110 void BaseCommandEnv::push( uno::Any const & /*Status*/ )
111 {
112 }
113 
114 void BaseCommandEnv::update( uno::Any const & /*Status */)
115 {
116 }
117 
119 {
120 }
121 
122 
124 {
125 }
126 
128  css::uno::Reference< css::task::XInteractionHandler> const & handler):
129  BaseCommandEnv(handler)
130 {
131 }
132 // XInteractionHandler
134  Reference< task::XInteractionRequest> const & xRequest )
135 {
136  uno::Any request( xRequest->getRequest() );
137  OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
138 
139  deployment::VersionException verExc;
140  deployment::LicenseException licExc;
141  deployment::InstallException instExc;
142 
143  bool approve = false;
144 
145  if ((request >>= verExc)
146  || (request >>= licExc)
147  || (request >>= instExc))
148  {
149  approve = true;
150  }
151 
152  handle_(approve, xRequest);
153 }
154 
155 
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)
162 {
163 }
164 // XInteractionHandler
166  Reference< task::XInteractionRequest> const & xRequest )
167 {
168  uno::Any request( xRequest->getRequest() );
169  OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
170 
171  deployment::LicenseException licExc;
172 
173  bool approve = false;
174 
175  if (request >>= licExc)
176  {
178  || m_repository == "bundled"
179  || licExc.AcceptBy == "admin")
180  {
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;
186  }
187  }
188 
189  handle_(approve, xRequest);
190 }
191 
192 
194  css::uno::Reference< css::task::XInteractionHandler> const & handler):
195  BaseCommandEnv(handler)
196 {
197 }
198 // XInteractionHandler
200  Reference< task::XInteractionRequest> const & xRequest )
201 {
202  uno::Any request( xRequest->getRequest() );
203  OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
204 
205  deployment::LicenseException licExc;
206 
207  bool approve = false;
208 
209  if (request >>= licExc)
210  {
211  approve = true;
212  }
213  handle_(approve, xRequest);
214 }
215 
217 {
218 }
219 
221  Reference< task::XInteractionRequest> const & xRequest )
222 {
223  uno::Any request( xRequest->getRequest() );
224  OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
225 
226  deployment::LicenseException licExc;
227  deployment::PlatformException platformExc;
228  deployment::DependencyException depExc;
229 
230  if (request >>= licExc)
231  {
232  handle_(true, xRequest); // approve = true
233  }
234  else if ((request >>= platformExc)
235  || (request >>= depExc))
236  {
237  m_Exception = request;
238  }
239  else
240  {
241  m_UnknownException = request;
242  }
243 }
244 
245 }
246 
247 /* 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
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)