1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <comphelper/interaction.hxx>
21 #include <framework/interaction.hxx>
24 using namespace ::com::sun::star
;
28 /*-************************************************************************************************************
29 @short declaration of special continuation for filter selection
30 @descr Sometimes filter detection during loading document failed. Then we need a possibility
31 to ask user for his decision. These continuation transport selected filter by user to
32 code user of interaction.
34 @attention This implementation could be used one times only. We don't support a resetable continuation yet!
35 Why? Normally interaction should show a filter selection dialog and ask user for his decision.
36 He can select any filter - then instances of these class will be called by handler ... or user
37 close dialog without any selection. Then another continuation should be slected by handler to
38 abort continuations ... Retrying isn't very useful here ... I think.
40 @implements XInteractionFilterSelect
42 @base ImplInheritanceHelper1
45 @devstatus ready to use
46 @threadsafe no (used on once position only!)
47 *//*-*************************************************************************************************************/
48 class ContinuationFilterSelect
: public comphelper::OInteraction
< ::com::sun::star::document::XInteractionFilterSelect
>
52 ContinuationFilterSelect();
56 virtual void SAL_CALL
setFilter( const OUString
& sFilter
) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
57 virtual OUString SAL_CALL
getFilter( ) throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
63 }; // class ContinuationFilterSelect
65 // initialize continuation with right start values
67 ContinuationFilterSelect::ContinuationFilterSelect()
68 : m_sFilter( OUString() )
72 // handler should use it after selection to set user specified filter for transport
74 void SAL_CALL
ContinuationFilterSelect::setFilter( const OUString
& sFilter
) throw( css::uno::RuntimeException
, std::exception
)
79 // read access to transported filter
81 OUString SAL_CALL
ContinuationFilterSelect::getFilter() throw( css::uno::RuntimeException
, std::exception
)
86 class RequestFilterSelect_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::task::XInteractionRequest
>
89 RequestFilterSelect_Impl( const OUString
& sURL
);
90 bool isAbort () const;
91 OUString
getFilter() const;
94 virtual ::com::sun::star::uno::Any SAL_CALL
getRequest() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
95 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > SAL_CALL
getContinuations() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
98 ::com::sun::star::uno::Any m_aRequest
;
99 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > m_lContinuations
;
100 comphelper::OInteractionAbort
* m_pAbort
;
101 ContinuationFilterSelect
* m_pFilter
;
104 // initialize instance with all necessary information
105 // We use it without any further checks on our member then ...!
107 RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString
& sURL
)
110 css::uno::Reference
< css::uno::XInterface
> temp2
;
111 css::document::NoSuchFilterRequest
aFilterRequest( temp
,
114 m_aRequest
<<= aFilterRequest
;
116 m_pAbort
= new comphelper::OInteractionAbort
;
117 m_pFilter
= new ContinuationFilterSelect
;
119 m_lContinuations
.realloc( 2 );
120 m_lContinuations
[0] = css::uno::Reference
< css::task::XInteractionContinuation
>( m_pAbort
);
121 m_lContinuations
[1] = css::uno::Reference
< css::task::XInteractionContinuation
>( m_pFilter
);
124 // return abort state of interaction
125 // If it is true, return value of method "getFilter()" will be unspecified then!
127 bool RequestFilterSelect_Impl::isAbort() const
129 return m_pAbort
->wasSelected();
132 // return user selected filter
133 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
135 OUString
RequestFilterSelect_Impl::getFilter() const
137 return m_pFilter
->getFilter();
140 // handler call it to get type of request
141 // Is hard coded to "please select filter" here. see ctor for further information.
143 css::uno::Any SAL_CALL
RequestFilterSelect_Impl::getRequest() throw( css::uno::RuntimeException
, std::exception
)
148 // handler call it to get possible continuations
149 // We support "abort/select_filter" only here.
150 // After interaction we support read access on these continuations on our c++ interface to
151 // return user decision.
153 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > SAL_CALL
RequestFilterSelect_Impl::getContinuations() throw( css::uno::RuntimeException
, std::exception
)
155 return m_lContinuations
;
158 RequestFilterSelect::RequestFilterSelect( const OUString
& sURL
)
160 pImp
= new RequestFilterSelect_Impl( sURL
);
164 RequestFilterSelect::~RequestFilterSelect()
169 // return abort state of interaction
170 // If it is true, return value of method "getFilter()" will be unspecified then!
172 bool RequestFilterSelect::isAbort() const
174 return pImp
->isAbort();
177 // return user selected filter
178 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
180 OUString
RequestFilterSelect::getFilter() const
182 return pImp
->getFilter();
185 uno::Reference
< task::XInteractionRequest
> RequestFilterSelect::GetRequest()
187 return uno::Reference
< task::XInteractionRequest
> (pImp
);
190 class InteractionRequest_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::task::XInteractionRequest
>
193 uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > m_lContinuations
;
196 InteractionRequest_Impl( const ::com::sun::star::uno::Any
& aRequest
,
197 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> >& lContinuations
)
199 m_aRequest
= aRequest
;
200 m_lContinuations
= lContinuations
;
203 virtual uno::Any SAL_CALL
getRequest() throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
204 virtual uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > SAL_CALL
getContinuations()
205 throw( uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
208 uno::Any SAL_CALL
InteractionRequest_Impl::getRequest() throw( uno::RuntimeException
, std::exception
)
213 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > SAL_CALL
InteractionRequest_Impl::getContinuations()
214 throw( uno::RuntimeException
, std::exception
)
216 return m_lContinuations
;
219 uno::Reference
< task::XInteractionRequest
> InteractionRequest::CreateRequest(
220 const uno::Any
& aRequest
, const uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> >& lContinuations
)
222 return new InteractionRequest_Impl( aRequest
, lContinuations
);
225 } // namespace framework
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */