1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 #include <comphelper/interaction.hxx>
31 #include <framework/interaction.hxx>
32 #include <general.h>
33 
34 using namespace ::com::sun::star;
35 
36 namespace framework{
37 
38 /*-************************************************************************************************************//**
39     @short          declaration of special continuation for filter selection
40     @descr          Sometimes filter detection during loading document failed. Then we need a possibility
41                     to ask user for his decision. These continuation transport selected filter by user to
42                     code user of interaction.
43 
44     @attention      This implementation could be used one times only. We don't support a resetable continuation yet!
45                     Why? Normally interaction should show a filter selection dialog and ask user for his decision.
46                     He can select any filter - then instances of these class will be called by handler ... or user
47                     close dialog without any selection. Then another continuation should be slected by handler to
48                     abort continuations ... Retrying isn't very useful here ... I think.
49 
50     @implements     XInteractionFilterSelect
51 
52     @base           ImplInheritanceHelper1
53                     ContinuationBase
54 
55     @devstatus      ready to use
56     @threadsafe     no (used on once position only!)
57 *//*-*************************************************************************************************************/
58 class ContinuationFilterSelect : public comphelper::OInteraction< ::com::sun::star::document::XInteractionFilterSelect >
59 {
60     // c++ interface
61     public:
62         ContinuationFilterSelect();
63 
64     // uno interface
65     public:
66         virtual void            SAL_CALL setFilter( const ::rtl::OUString& sFilter ) throw( ::com::sun::star::uno::RuntimeException );
67         virtual ::rtl::OUString SAL_CALL getFilter(                                ) throw( ::com::sun::star::uno::RuntimeException );
68 
69     // member
70     private:
71         ::rtl::OUString m_sFilter;
72 
73 };  // class ContinuationFilterSelect
74 
75 
76 //---------------------------------------------------------------------------------------------------------
77 // initialize continuation with right start values
78 //---------------------------------------------------------------------------------------------------------
ContinuationFilterSelect()79 ContinuationFilterSelect::ContinuationFilterSelect()
80     : m_sFilter( ::rtl::OUString() )
81 {
82 }
83 
84 //---------------------------------------------------------------------------------------------------------
85 // handler should use it after selection to set user specified filter for transport
86 //---------------------------------------------------------------------------------------------------------
setFilter(const::rtl::OUString & sFilter)87 void SAL_CALL ContinuationFilterSelect::setFilter( const ::rtl::OUString& sFilter ) throw( css::uno::RuntimeException )
88 {
89     m_sFilter = sFilter;
90 }
91 
92 //---------------------------------------------------------------------------------------------------------
93 // read access to transported filter
94 //---------------------------------------------------------------------------------------------------------
getFilter()95 ::rtl::OUString SAL_CALL ContinuationFilterSelect::getFilter() throw( css::uno::RuntimeException )
96 {
97     return m_sFilter;
98 }
99 
100 class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
101 {
102 public:
103     RequestFilterSelect_Impl( const ::rtl::OUString& sURL );
104     sal_Bool        isAbort  () const;
105     ::rtl::OUString getFilter() const;
106 
107 public:
108     virtual ::com::sun::star::uno::Any SAL_CALL getRequest() throw( ::com::sun::star::uno::RuntimeException );
109     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 );
110 
111 private:
112     ::com::sun::star::uno::Any                                                                                                 m_aRequest      ;
113     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >    m_lContinuations;
114     comphelper::OInteractionAbort* m_pAbort;
115     ContinuationFilterSelect* m_pFilter;
116 };
117 
118 //---------------------------------------------------------------------------------------------------------
119 // initialize instance with all necessary informations
120 // We use it without any further checks on our member then ...!
121 //---------------------------------------------------------------------------------------------------------
RequestFilterSelect_Impl(const::rtl::OUString & sURL)122 RequestFilterSelect_Impl::RequestFilterSelect_Impl( const ::rtl::OUString& sURL )
123 {
124 	::rtl::OUString temp;
125 	css::uno::Reference< css::uno::XInterface > temp2;
126     css::document::NoSuchFilterRequest aFilterRequest( temp                             ,
127                                                        temp2							,
128                                                        sURL                                          );
129     m_aRequest <<= aFilterRequest;
130 
131     m_pAbort  = new comphelper::OInteractionAbort;
132     m_pFilter = new ContinuationFilterSelect;
133 
134     m_lContinuations.realloc( 2 );
135     m_lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >( m_pAbort  );
136     m_lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >( m_pFilter );
137 }
138 
139 //---------------------------------------------------------------------------------------------------------
140 // return abort state of interaction
141 // If it is true, return value of method "getFilter()" will be unspecified then!
142 //---------------------------------------------------------------------------------------------------------
isAbort() const143 sal_Bool RequestFilterSelect_Impl::isAbort() const
144 {
145     return m_pAbort->wasSelected();
146 }
147 
148 //---------------------------------------------------------------------------------------------------------
149 // return user selected filter
150 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
151 //---------------------------------------------------------------------------------------------------------
getFilter() const152 ::rtl::OUString RequestFilterSelect_Impl::getFilter() const
153 {
154     return m_pFilter->getFilter();
155 }
156 
157 //---------------------------------------------------------------------------------------------------------
158 // handler call it to get type of request
159 // Is hard coded to "please select filter" here. see ctor for further informations.
160 //---------------------------------------------------------------------------------------------------------
getRequest()161 css::uno::Any SAL_CALL RequestFilterSelect_Impl::getRequest() throw( css::uno::RuntimeException )
162 {
163     return m_aRequest;
164 }
165 
166 //---------------------------------------------------------------------------------------------------------
167 // handler call it to get possible continuations
168 // We support "abort/select_filter" only here.
169 // After interaction we support read access on these continuations on our c++ interface to
170 // return user decision.
171 //---------------------------------------------------------------------------------------------------------
getContinuations()172 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations() throw( css::uno::RuntimeException )
173 {
174     return m_lContinuations;
175 }
176 
177 
RequestFilterSelect(const::rtl::OUString & sURL)178 RequestFilterSelect::RequestFilterSelect( const ::rtl::OUString& sURL )
179 {
180     pImp = new RequestFilterSelect_Impl( sURL );
181     pImp->acquire();
182 }
183 
~RequestFilterSelect()184 RequestFilterSelect::~RequestFilterSelect()
185 {
186     pImp->release();
187 }
188 
189 
190 //---------------------------------------------------------------------------------------------------------
191 // return abort state of interaction
192 // If it is true, return value of method "getFilter()" will be unspecified then!
193 //---------------------------------------------------------------------------------------------------------
isAbort() const194 sal_Bool RequestFilterSelect::isAbort() const
195 {
196     return pImp->isAbort();
197 }
198 
199 //---------------------------------------------------------------------------------------------------------
200 // return user selected filter
201 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
202 //---------------------------------------------------------------------------------------------------------
getFilter() const203 ::rtl::OUString RequestFilterSelect::getFilter() const
204 {
205     return pImp->getFilter();
206 }
207 
GetRequest()208 uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest()
209 {
210     return uno::Reference < task::XInteractionRequest > (pImp);
211 }
212 
213 /*
214 class RequestAmbigousFilter_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
215 {
216 public:
217     RequestAmbigousFilter_Impl( const ::rtl::OUString& sURL            ,
218                             const ::rtl::OUString& sSelectedFilter ,
219                             const ::rtl::OUString& sDetectedFilter );
220     sal_Bool        isAbort  () const;
221     ::rtl::OUString getFilter() const;
222 
223     virtual ::com::sun::star::uno::Any SAL_CALL getRequest () throw( ::com::sun::star::uno::RuntimeException );
224     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 );
225 
226     ::com::sun::star::uno::Any                                                                                                 m_aRequest      ;
227     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > >    m_lContinuations;
228     ContinuationAbort*                                                                                                         m_pAbort        ;
229     ContinuationFilterSelect*                                                                                                  m_pFilter       ;
230 };
231 
232 RequestAmbigousFilter::RequestAmbigousFilter( const ::rtl::OUString& sURL, const ::rtl::OUString& sSelectedFilter,
233     const ::rtl::OUString& sDetectedFilter )
234 {
235     pImp = new RequestAmbigousFilter_Impl( sURL, sSelectedFilter, sDetectedFilter );
236     pImp->acquire();
237 }
238 
239 RequestAmbigousFilter::~RequestAmbigousFilter()
240 {
241     pImp->release();
242 }
243 
244 sal_Bool RequestAmbigousFilter::isAbort() const
245 {
246     return pImp->isAbort();
247 }
248 
249 //---------------------------------------------------------------------------------------------------------
250 // return user selected filter
251 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
252 //---------------------------------------------------------------------------------------------------------
253 ::rtl::OUString RequestAmbigousFilter::getFilter() const
254 {
255     return pImp->getFilter();
256 }
257 
258 uno::Reference < task::XInteractionRequest > RequestAmbigousFilter::GetRequest()
259 {
260     return uno::Reference < task::XInteractionRequest > (pImp);
261 }
262 
263 //---------------------------------------------------------------------------------------------------------
264 // initialize instance with all necessary informations
265 // We use it without any further checks on our member then ...!
266 //---------------------------------------------------------------------------------------------------------
267 RequestAmbigousFilter_Impl::RequestAmbigousFilter_Impl( const ::rtl::OUString& sURL            ,
268                                               const ::rtl::OUString& sSelectedFilter ,
269                                               const ::rtl::OUString& sDetectedFilter )
270 {
271 	::rtl::OUString temp;
272 	css::uno::Reference< css::uno::XInterface > temp2;
273     css::document::AmbigousFilterRequest aFilterRequest( temp                             ,
274                                                          temp2 ,
275                                                          sURL                                          ,
276                                                          sSelectedFilter                               ,
277                                                          sDetectedFilter                               );
278     m_aRequest <<= aFilterRequest;
279 
280     m_pAbort  = new ContinuationAbort       ;
281     m_pFilter = new ContinuationFilterSelect;
282 
283     m_lContinuations.realloc( 2 );
284     m_lContinuations[0] = css::uno::Reference< css::task::XInteractionContinuation >( m_pAbort  );
285     m_lContinuations[1] = css::uno::Reference< css::task::XInteractionContinuation >( m_pFilter );
286 }
287 
288 //---------------------------------------------------------------------------------------------------------
289 // return abort state of interaction
290 // If it is true, return value of method "getFilter()" will be unspecified then!
291 //---------------------------------------------------------------------------------------------------------
292 sal_Bool RequestAmbigousFilter_Impl::isAbort() const
293 {
294     return m_pAbort->isSelected();
295 }
296 
297 //---------------------------------------------------------------------------------------------------------
298 // return user selected filter
299 // Return value valid for non aborted interaction only. Please check "isAbort()" before you call these ony!
300 //---------------------------------------------------------------------------------------------------------
301 ::rtl::OUString RequestAmbigousFilter_Impl::getFilter() const
302 {
303     return m_pFilter->getFilter();
304 }
305 
306 //---------------------------------------------------------------------------------------------------------
307 // handler call it to get type of request
308 // Is hard coded to "please select filter" here. see ctor for further informations.
309 //---------------------------------------------------------------------------------------------------------
310 css::uno::Any SAL_CALL RequestAmbigousFilter_Impl::getRequest() throw( css::uno::RuntimeException )
311 {
312     return m_aRequest;
313 }
314 
315 //---------------------------------------------------------------------------------------------------------
316 // handler call it to get possible continuations
317 // We support "abort/select_filter" only here.
318 // After interaction we support read access on these continuations on our c++ interface to
319 // return user decision.
320 //---------------------------------------------------------------------------------------------------------
321 css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestAmbigousFilter_Impl::getContinuations() throw( css::uno::RuntimeException )
322 {
323     return m_lContinuations;
324 }
325 */
326 
327 class InteractionRequest_Impl : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
328 {
329     uno::Any m_aRequest;
330     uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > m_lContinuations;
331 
332 public:
InteractionRequest_Impl(const::com::sun::star::uno::Any & aRequest,const::com::sun::star::uno::Sequence<::com::sun::star::uno::Reference<::com::sun::star::task::XInteractionContinuation>> lContinuations)333     InteractionRequest_Impl( const ::com::sun::star::uno::Any& aRequest,
334         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionContinuation > > lContinuations )
335     {
336         m_aRequest = aRequest;
337         m_lContinuations = lContinuations;
338     }
339 
340     virtual uno::Any SAL_CALL getRequest() throw( uno::RuntimeException );
341     virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations()
342             throw( uno::RuntimeException );
343 };
344 
getRequest()345 uno::Any SAL_CALL InteractionRequest_Impl::getRequest() throw( uno::RuntimeException )
346 {
347     return m_aRequest;
348 }
349 
getContinuations()350 uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
351     throw( uno::RuntimeException )
352 {
353     return m_lContinuations;
354 }
355 
CreateRequest(const uno::Any & aRequest,const uno::Sequence<uno::Reference<task::XInteractionContinuation>> lContinuations)356 uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
357     const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > > lContinuations )
358 {
359     return new InteractionRequest_Impl( aRequest, lContinuations );
360 }
361 
362 }       //  namespace framework
363