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