1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2722ceddSAndrew Rist * distributed with this work for additional information
6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at
10*2722ceddSAndrew Rist *
11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist *
13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the
17*2722ceddSAndrew Rist * specific language governing permissions and limitations
18*2722ceddSAndrew Rist * under the License.
19*2722ceddSAndrew Rist *
20*2722ceddSAndrew Rist *************************************************************/
21*2722ceddSAndrew Rist
22*2722ceddSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "com/sun/star/deployment/VersionException.hpp"
28cdf0e10cSrcweir #include "com/sun/star/deployment/LicenseException.hpp"
29cdf0e10cSrcweir #include "com/sun/star/deployment/InstallException.hpp"
30cdf0e10cSrcweir #include "com/sun/star/deployment/DependencyException.hpp"
31cdf0e10cSrcweir #include "com/sun/star/deployment/PlatformException.hpp"
32cdf0e10cSrcweir #include "com/sun/star/task/XInteractionApprove.hpp"
33cdf0e10cSrcweir #include "com/sun/star/task/XInteractionAbort.hpp"
34cdf0e10cSrcweir #include "com/sun/star/task/XInteractionHandler.hpp"
35cdf0e10cSrcweir #include "com/sun/star/ucb/XCommandEnvironment.hpp"
36cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
37cdf0e10cSrcweir #include "dp_commandenvironments.hxx"
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace deployment = com::sun::star::deployment;
40cdf0e10cSrcweir namespace lang = com::sun::star::lang;
41cdf0e10cSrcweir namespace task = com::sun::star::task;
42cdf0e10cSrcweir namespace ucb = com::sun::star::ucb;
43cdf0e10cSrcweir namespace uno = com::sun::star::uno;
44cdf0e10cSrcweir namespace css = com::sun::star;
45cdf0e10cSrcweir
46cdf0e10cSrcweir #define OUSTR(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))
47cdf0e10cSrcweir
48cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
49cdf0e10cSrcweir using ::rtl::OUString;
50cdf0e10cSrcweir
51cdf0e10cSrcweir namespace dp_manager {
52cdf0e10cSrcweir
BaseCommandEnv()53cdf0e10cSrcweir BaseCommandEnv::BaseCommandEnv()
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
BaseCommandEnv(Reference<task::XInteractionHandler> const & handler)57cdf0e10cSrcweir BaseCommandEnv::BaseCommandEnv(
58cdf0e10cSrcweir Reference< task::XInteractionHandler> const & handler)
59cdf0e10cSrcweir : m_forwardHandler(handler)
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
~BaseCommandEnv()63cdf0e10cSrcweir BaseCommandEnv::~BaseCommandEnv()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir // XCommandEnvironment
67cdf0e10cSrcweir //______________________________________________________________________________
getInteractionHandler()68cdf0e10cSrcweir Reference<task::XInteractionHandler> BaseCommandEnv::getInteractionHandler()
69cdf0e10cSrcweir throw (uno::RuntimeException)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir return this;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir //______________________________________________________________________________
getProgressHandler()75cdf0e10cSrcweir Reference<ucb::XProgressHandler> BaseCommandEnv::getProgressHandler()
76cdf0e10cSrcweir throw (uno::RuntimeException)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir return this;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
handle(Reference<task::XInteractionRequest> const &)81cdf0e10cSrcweir void BaseCommandEnv::handle(
82cdf0e10cSrcweir Reference< task::XInteractionRequest> const & /*xRequest*/ )
83cdf0e10cSrcweir throw (uno::RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
handle_(bool approve,bool abort,Reference<task::XInteractionRequest> const & xRequest)87cdf0e10cSrcweir void BaseCommandEnv::handle_(bool approve, bool abort,
88cdf0e10cSrcweir Reference< task::XInteractionRequest> const & xRequest )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir if (approve == false && abort == false)
91cdf0e10cSrcweir {
92cdf0e10cSrcweir //not handled so far -> forwarding
93cdf0e10cSrcweir if (m_forwardHandler.is())
94cdf0e10cSrcweir m_forwardHandler->handle(xRequest);
95cdf0e10cSrcweir else
96cdf0e10cSrcweir return; //cannot handle
97cdf0e10cSrcweir }
98cdf0e10cSrcweir else
99cdf0e10cSrcweir {
100cdf0e10cSrcweir // select:
101cdf0e10cSrcweir uno::Sequence< Reference< task::XInteractionContinuation > > conts(
102cdf0e10cSrcweir xRequest->getContinuations() );
103cdf0e10cSrcweir Reference< task::XInteractionContinuation > const * pConts =
104cdf0e10cSrcweir conts.getConstArray();
105cdf0e10cSrcweir sal_Int32 len = conts.getLength();
106cdf0e10cSrcweir for ( sal_Int32 pos = 0; pos < len; ++pos )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir if (approve) {
109cdf0e10cSrcweir Reference< task::XInteractionApprove > xInteractionApprove(
110cdf0e10cSrcweir pConts[ pos ], uno::UNO_QUERY );
111cdf0e10cSrcweir if (xInteractionApprove.is()) {
112cdf0e10cSrcweir xInteractionApprove->select();
113cdf0e10cSrcweir // don't query again for ongoing continuations:
114cdf0e10cSrcweir approve = false;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir else if (abort) {
118cdf0e10cSrcweir Reference< task::XInteractionAbort > xInteractionAbort(
119cdf0e10cSrcweir pConts[ pos ], uno::UNO_QUERY );
120cdf0e10cSrcweir if (xInteractionAbort.is()) {
121cdf0e10cSrcweir xInteractionAbort->select();
122cdf0e10cSrcweir // don't query again for ongoing continuations:
123cdf0e10cSrcweir abort = false;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir // XProgressHandler
push(uno::Any const &)132cdf0e10cSrcweir void BaseCommandEnv::push( uno::Any const & /*Status*/ )
133cdf0e10cSrcweir throw (uno::RuntimeException)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
137cdf0e10cSrcweir
update(uno::Any const &)138cdf0e10cSrcweir void BaseCommandEnv::update( uno::Any const & /*Status */)
139cdf0e10cSrcweir throw (uno::RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
pop()143cdf0e10cSrcweir void BaseCommandEnv::pop() throw (uno::RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir }
146cdf0e10cSrcweir //==============================================================================
147cdf0e10cSrcweir
TmpRepositoryCommandEnv()148cdf0e10cSrcweir TmpRepositoryCommandEnv::TmpRepositoryCommandEnv()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
TmpRepositoryCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler)152cdf0e10cSrcweir TmpRepositoryCommandEnv::TmpRepositoryCommandEnv(
153cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler> const & handler):
154cdf0e10cSrcweir BaseCommandEnv(handler)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir }
157cdf0e10cSrcweir // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)158cdf0e10cSrcweir void TmpRepositoryCommandEnv::handle(
159cdf0e10cSrcweir Reference< task::XInteractionRequest> const & xRequest )
160cdf0e10cSrcweir throw (uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir uno::Any request( xRequest->getRequest() );
163cdf0e10cSrcweir OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
164cdf0e10cSrcweir
165cdf0e10cSrcweir deployment::VersionException verExc;
166cdf0e10cSrcweir deployment::LicenseException licExc;
167cdf0e10cSrcweir deployment::InstallException instExc;
168cdf0e10cSrcweir
169cdf0e10cSrcweir bool approve = false;
170cdf0e10cSrcweir bool abort = false;
171cdf0e10cSrcweir
172cdf0e10cSrcweir if ((request >>= verExc)
173cdf0e10cSrcweir || (request >>= licExc)
174cdf0e10cSrcweir || (request >>= instExc))
175cdf0e10cSrcweir {
176cdf0e10cSrcweir approve = true;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir handle_(approve, abort, xRequest);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir //================================================================================
182cdf0e10cSrcweir
LicenseCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler,bool bSuppressLicense,OUString const & repository)183cdf0e10cSrcweir LicenseCommandEnv::LicenseCommandEnv(
184cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler> const & handler,
185cdf0e10cSrcweir bool bSuppressLicense,
186cdf0e10cSrcweir OUString const & repository):
187cdf0e10cSrcweir BaseCommandEnv(handler), m_repository(repository),
188cdf0e10cSrcweir m_bSuppressLicense(bSuppressLicense)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir }
191cdf0e10cSrcweir // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)192cdf0e10cSrcweir void LicenseCommandEnv::handle(
193cdf0e10cSrcweir Reference< task::XInteractionRequest> const & xRequest )
194cdf0e10cSrcweir throw (uno::RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir uno::Any request( xRequest->getRequest() );
197cdf0e10cSrcweir OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
198cdf0e10cSrcweir
199cdf0e10cSrcweir
200cdf0e10cSrcweir deployment::LicenseException licExc;
201cdf0e10cSrcweir
202cdf0e10cSrcweir bool approve = false;
203cdf0e10cSrcweir bool abort = false;
204cdf0e10cSrcweir
205cdf0e10cSrcweir if (request >>= licExc)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir if (m_bSuppressLicense
208cdf0e10cSrcweir || m_repository.equals(OUSTR("bundled"))
209cdf0e10cSrcweir || licExc.AcceptBy.equals(OUSTR("admin")))
210cdf0e10cSrcweir {
211cdf0e10cSrcweir //always approve in bundled case, because we do not support
212cdf0e10cSrcweir //showing licenses anyway.
213cdf0e10cSrcweir //The "admin" already accepted the license when installing the
214cdf0e10cSrcweir // shared extension
215cdf0e10cSrcweir approve = true;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
219cdf0e10cSrcweir handle_(approve, abort, xRequest);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
222cdf0e10cSrcweir //================================================================================
223cdf0e10cSrcweir //================================================================================
224cdf0e10cSrcweir
NoLicenseCommandEnv(css::uno::Reference<css::task::XInteractionHandler> const & handler)225cdf0e10cSrcweir NoLicenseCommandEnv::NoLicenseCommandEnv(
226cdf0e10cSrcweir css::uno::Reference< css::task::XInteractionHandler> const & handler):
227cdf0e10cSrcweir BaseCommandEnv(handler)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir }
230cdf0e10cSrcweir // XInteractionHandler
handle(Reference<task::XInteractionRequest> const & xRequest)231cdf0e10cSrcweir void NoLicenseCommandEnv::handle(
232cdf0e10cSrcweir Reference< task::XInteractionRequest> const & xRequest )
233cdf0e10cSrcweir throw (uno::RuntimeException)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir uno::Any request( xRequest->getRequest() );
236cdf0e10cSrcweir OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
237cdf0e10cSrcweir
238cdf0e10cSrcweir
239cdf0e10cSrcweir deployment::LicenseException licExc;
240cdf0e10cSrcweir
241cdf0e10cSrcweir bool approve = false;
242cdf0e10cSrcweir bool abort = false;
243cdf0e10cSrcweir
244cdf0e10cSrcweir if (request >>= licExc)
245cdf0e10cSrcweir {
246cdf0e10cSrcweir approve = true;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir handle_(approve, abort, xRequest);
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
251cdf0e10cSrcweir // SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv(
252cdf0e10cSrcweir // css::uno::Reference< css::task::XInteractionHandler> const & handler):
253cdf0e10cSrcweir // BaseCommandEnv(handler)
254cdf0e10cSrcweir // {
255cdf0e10cSrcweir // }
SilentCheckPrerequisitesCommandEnv()256cdf0e10cSrcweir SilentCheckPrerequisitesCommandEnv::SilentCheckPrerequisitesCommandEnv()
257cdf0e10cSrcweir {
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
handle(Reference<task::XInteractionRequest> const & xRequest)260cdf0e10cSrcweir void SilentCheckPrerequisitesCommandEnv::handle(
261cdf0e10cSrcweir Reference< task::XInteractionRequest> const & xRequest )
262cdf0e10cSrcweir throw (uno::RuntimeException)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir uno::Any request( xRequest->getRequest() );
265cdf0e10cSrcweir OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
266cdf0e10cSrcweir
267cdf0e10cSrcweir deployment::LicenseException licExc;
268cdf0e10cSrcweir deployment::PlatformException platformExc;
269cdf0e10cSrcweir deployment::DependencyException depExc;
270cdf0e10cSrcweir bool approve = false;
271cdf0e10cSrcweir bool abort = false;
272cdf0e10cSrcweir
273cdf0e10cSrcweir if (request >>= licExc)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir approve = true;
276cdf0e10cSrcweir handle_(approve, abort, xRequest);
277cdf0e10cSrcweir }
278cdf0e10cSrcweir else if ((request >>= platformExc)
279cdf0e10cSrcweir || (request >>= depExc))
280cdf0e10cSrcweir {
281cdf0e10cSrcweir m_Exception = request;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir else
284cdf0e10cSrcweir {
285cdf0e10cSrcweir m_UnknownException = request;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir }
288cdf0e10cSrcweir // NoExceptionCommandEnv::NoExceptionCommandEnv(
289cdf0e10cSrcweir // css::uno::Reference< css::task::XInteractionHandler> const & handler,
290cdf0e10cSrcweir // css::uno::Type const & type):
291cdf0e10cSrcweir // BaseCommandEnv(handler),
292cdf0e10cSrcweir // m_type(type)
293cdf0e10cSrcweir // {
294cdf0e10cSrcweir // }
295cdf0e10cSrcweir // // XInteractionHandler
296cdf0e10cSrcweir // void NoExceptionCommandEnv::handle(
297cdf0e10cSrcweir // Reference< task::XInteractionRequest> const & xRequest )
298cdf0e10cSrcweir // throw (uno::RuntimeException)
299cdf0e10cSrcweir // {
300cdf0e10cSrcweir // uno::Any request( xRequest->getRequest() );
301cdf0e10cSrcweir // OSL_ASSERT( request.getValueTypeClass() == uno::TypeClass_EXCEPTION );
302cdf0e10cSrcweir
303cdf0e10cSrcweir
304cdf0e10cSrcweir // deployment::LicenseException licExc;
305cdf0e10cSrcweir
306cdf0e10cSrcweir // bool approve = false;
307cdf0e10cSrcweir // bool abort = false;
308cdf0e10cSrcweir
309cdf0e10cSrcweir // if (request.getValueType() == m_type)
310cdf0e10cSrcweir // {
311cdf0e10cSrcweir // approve = true;
312cdf0e10cSrcweir // }
313cdf0e10cSrcweir // handle_(approve, abort, xRequest);
314cdf0e10cSrcweir // }
315cdf0e10cSrcweir
316cdf0e10cSrcweir
317cdf0e10cSrcweir
318cdf0e10cSrcweir } // namespace dp_manager
319cdf0e10cSrcweir
320cdf0e10cSrcweir
321