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? Normaly 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
);
57 virtual OUString SAL_CALL
getFilter( ) throw( ::com::sun::star::uno::RuntimeException
);
63 }; // class ContinuationFilterSelect
66 //---------------------------------------------------------------------------------------------------------
67 // initialize continuation with right start values
68 //---------------------------------------------------------------------------------------------------------
69 ContinuationFilterSelect::ContinuationFilterSelect()
70 : m_sFilter( OUString() )
74 //---------------------------------------------------------------------------------------------------------
75 // handler should use it after selection to set user specified filter for transport
76 //---------------------------------------------------------------------------------------------------------
77 void SAL_CALL
ContinuationFilterSelect::setFilter( const OUString
& sFilter
) throw( css::uno::RuntimeException
)
82 //---------------------------------------------------------------------------------------------------------
83 // read access to transported filter
84 //---------------------------------------------------------------------------------------------------------
85 OUString SAL_CALL
ContinuationFilterSelect::getFilter() throw( css::uno::RuntimeException
)
90 class RequestFilterSelect_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::task::XInteractionRequest
>
93 RequestFilterSelect_Impl( const OUString
& sURL
);
94 sal_Bool
isAbort () const;
95 OUString
getFilter() const;
98 virtual ::com::sun::star::uno::Any SAL_CALL
getRequest() throw( ::com::sun::star::uno::RuntimeException
);
99 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
);
102 ::com::sun::star::uno::Any m_aRequest
;
103 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > m_lContinuations
;
104 comphelper::OInteractionAbort
* m_pAbort
;
105 ContinuationFilterSelect
* m_pFilter
;
108 //---------------------------------------------------------------------------------------------------------
109 // initialize instance with all necessary information
110 // We use it without any further checks on our member then ...!
111 //---------------------------------------------------------------------------------------------------------
112 RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString
& sURL
)
115 css::uno::Reference
< css::uno::XInterface
> temp2
;
116 css::document::NoSuchFilterRequest
aFilterRequest( temp
,
119 m_aRequest
<<= aFilterRequest
;
121 m_pAbort
= new comphelper::OInteractionAbort
;
122 m_pFilter
= new ContinuationFilterSelect
;
124 m_lContinuations
.realloc( 2 );
125 m_lContinuations
[0] = css::uno::Reference
< css::task::XInteractionContinuation
>( m_pAbort
);
126 m_lContinuations
[1] = css::uno::Reference
< css::task::XInteractionContinuation
>( m_pFilter
);
129 //---------------------------------------------------------------------------------------------------------
130 // return abort state of interaction
131 // If it is true, return value of method "getFilter()" will be unspecified then!
132 //---------------------------------------------------------------------------------------------------------
133 sal_Bool
RequestFilterSelect_Impl::isAbort() const
135 return m_pAbort
->wasSelected();
138 //---------------------------------------------------------------------------------------------------------
139 // return user selected filter
140 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
141 //---------------------------------------------------------------------------------------------------------
142 OUString
RequestFilterSelect_Impl::getFilter() const
144 return m_pFilter
->getFilter();
147 //---------------------------------------------------------------------------------------------------------
148 // handler call it to get type of request
149 // Is hard coded to "please select filter" here. see ctor for further information.
150 //---------------------------------------------------------------------------------------------------------
151 css::uno::Any SAL_CALL
RequestFilterSelect_Impl::getRequest() throw( css::uno::RuntimeException
)
156 //---------------------------------------------------------------------------------------------------------
157 // handler call it to get possible continuations
158 // We support "abort/select_filter" only here.
159 // After interaction we support read access on these continuations on our c++ interface to
160 // return user decision.
161 //---------------------------------------------------------------------------------------------------------
162 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > SAL_CALL
RequestFilterSelect_Impl::getContinuations() throw( css::uno::RuntimeException
)
164 return m_lContinuations
;
168 RequestFilterSelect::RequestFilterSelect( const OUString
& sURL
)
170 pImp
= new RequestFilterSelect_Impl( sURL
);
174 RequestFilterSelect::~RequestFilterSelect()
180 //---------------------------------------------------------------------------------------------------------
181 // return abort state of interaction
182 // If it is true, return value of method "getFilter()" will be unspecified then!
183 //---------------------------------------------------------------------------------------------------------
184 sal_Bool
RequestFilterSelect::isAbort() const
186 return pImp
->isAbort();
189 //---------------------------------------------------------------------------------------------------------
190 // return user selected filter
191 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
192 //---------------------------------------------------------------------------------------------------------
193 OUString
RequestFilterSelect::getFilter() const
195 return pImp
->getFilter();
198 uno::Reference
< task::XInteractionRequest
> RequestFilterSelect::GetRequest()
200 return uno::Reference
< task::XInteractionRequest
> (pImp
);
203 class InteractionRequest_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::task::XInteractionRequest
>
206 uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > m_lContinuations
;
209 InteractionRequest_Impl( const ::com::sun::star::uno::Any
& aRequest
,
210 const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Reference
< ::com::sun::star::task::XInteractionContinuation
> > lContinuations
)
212 m_aRequest
= aRequest
;
213 m_lContinuations
= lContinuations
;
216 virtual uno::Any SAL_CALL
getRequest() throw( uno::RuntimeException
);
217 virtual uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > SAL_CALL
getContinuations()
218 throw( uno::RuntimeException
);
221 uno::Any SAL_CALL
InteractionRequest_Impl::getRequest() throw( uno::RuntimeException
)
226 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > SAL_CALL
InteractionRequest_Impl::getContinuations()
227 throw( uno::RuntimeException
)
229 return m_lContinuations
;
232 uno::Reference
< task::XInteractionRequest
> InteractionRequest::CreateRequest(
233 const uno::Any
& aRequest
, const uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > lContinuations
)
235 return new InteractionRequest_Impl( aRequest
, lContinuations
);
238 } // namespace framework
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */