1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "com/sun/star/beans/XPropertyAccess.hpp"
30 #include "com/sun/star/container/XContainerQuery.hpp"
31 #include "com/sun/star/container/XNameContainer.hpp"
32 #include "com/sun/star/document/AmbigousFilterRequest.hpp"
33 #include "com/sun/star/document/FilterOptionsRequest.hpp"
34 #include "com/sun/star/document/NoSuchFilterRequest.hpp"
35 #include "com/sun/star/document/XImporter.hpp"
36 #include "com/sun/star/document/XInteractionFilterOptions.hpp"
37 #include "com/sun/star/document/XInteractionFilterSelect.hpp"
38 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
39 #include "com/sun/star/task/XInteractionAbort.hpp"
40 #include "com/sun/star/task/XInteractionRequest.hpp"
41 #include "com/sun/star/ui/dialogs/XExecutableDialog.hpp"
43 #include "osl/mutex.hxx"
44 #include "comphelper/sequenceashashmap.hxx"
45 #include "vcl/svapp.hxx"
47 #include "getcontinuations.hxx"
52 using namespace com::sun::star
;
59 rtl::OUString
const & rURL
,
60 uui::FilterNameList
const & rFilters
,
61 rtl::OUString
& rFilter
)
62 SAL_THROW((uno::RuntimeException
))
66 SolarMutexGuard aGuard
;
68 std::auto_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
70 std::auto_ptr
< uui::FilterDialog
> xDialog(
71 new uui::FilterDialog(pParent
, xManager
.get()));
73 xDialog
->SetURL(rURL
);
74 xDialog
->ChangeFilters(&rFilters
);
76 uui::FilterNameListPtr pSelected
= rFilters
.end();
77 if( xDialog
->AskForFilter( pSelected
) )
79 rFilter
= pSelected
->sInternal
;
82 catch (std::bad_alloc
const &)
84 throw uno::RuntimeException(
85 rtl::OUString("out of memory"),
86 uno::Reference
< uno::XInterface
>());
91 handleNoSuchFilterRequest_(
93 uno::Reference
< lang::XMultiServiceFactory
> const & xServiceFactory
,
94 document::NoSuchFilterRequest
const & rRequest
,
95 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
97 SAL_THROW((uno::RuntimeException
))
99 uno::Reference
< task::XInteractionAbort
> xAbort
;
100 uno::Reference
< document::XInteractionFilterSelect
> xFilterTransport
;
101 getContinuations(rContinuations
, &xAbort
, &xFilterTransport
);
103 // check neccessary resources - if they don't exist - abort or
104 // break this operation
108 if (!xFilterTransport
.is())
114 uno::Reference
< container::XContainerQuery
> xFilterContainer
;
117 xFilterContainer
.set( xServiceFactory
->createInstance(
118 ::rtl::OUString( "com.sun.star.document.FilterFactory") ),
121 catch ( uno::Exception
const & )
125 if (!xFilterContainer
.is())
131 uui::FilterNameList lNames
;
133 // Note: We look for all filters here which match the following criteria:
134 // - they are import filters as minimum (of course they can
135 // support export too)
136 // - we don't show any filter which are flagged as "don't show it
137 // at the UI" or "they are not installed"
138 // - we ignore filters, which have not set any valid
139 // DocumentService (e.g. our pure graphic filters)
140 // - we show it sorted by her UIName's
141 // - We don't use the order flag or prefer default filters.
142 // (Because this list shows all filters and the user should
143 // find his filter very easy by his UIName ...)
144 // - We use "_query_all" here ... but we filter graphic filters
145 // out by using DocumentService property later!
146 uno::Reference
< container::XEnumeration
> xFilters
147 = xFilterContainer
->createSubSetEnumerationByQuery(
148 ::rtl::OUString( "_query_all:sort_prop=uiname:iflags=1:eflags=143360"));
149 while (xFilters
->hasMoreElements())
153 ::comphelper::SequenceAsHashMap
lProps(xFilters
->nextElement());
154 uui::FilterNamePair aPair
;
156 aPair
.sInternal
= lProps
.getUnpackedValueOrDefault(
157 rtl::OUString("Name"), ::rtl::OUString());
158 aPair
.sUI
= lProps
.getUnpackedValueOrDefault(
159 rtl::OUString("UIName"), ::rtl::OUString());
160 if ( (!aPair
.sInternal
.Len()) || (!aPair
.sUI
.Len() ) )
164 lNames
.push_back( aPair
);
166 catch(const uno::RuntimeException
&)
170 catch(const uno::Exception
&)
176 // no list available for showing
177 // -> abort operation
184 // let the user select the right filter
185 rtl::OUString sSelectedFilter
;
186 executeFilterDialog( pParent
,
191 // If he doesn't select anyone
192 // -> abort operation
193 if (sSelectedFilter
.isEmpty())
199 // otherwise set it for return
200 xFilterTransport
->setFilter( sSelectedFilter
);
201 xFilterTransport
->select();
205 handleAmbigousFilterRequest_(
207 uno::Reference
< lang::XMultiServiceFactory
> const & xServiceFactory
,
208 document::AmbigousFilterRequest
const & rRequest
,
211 task::XInteractionContinuation
> > const & rContinuations
)
212 SAL_THROW((uno::RuntimeException
))
214 uno::Reference
< task::XInteractionAbort
> xAbort
;
215 uno::Reference
< document::XInteractionFilterSelect
> xFilterTransport
;
216 getContinuations(rContinuations
, &xAbort
, &xFilterTransport
);
218 uui::FilterNameList lNames
;
220 uno::Reference
< container::XNameContainer
> xFilterContainer
;
223 xFilterContainer
.set( xServiceFactory
->createInstance(
224 ::rtl::OUString( "com.sun.star.document.FilterFactory") ),
227 catch ( uno::Exception
& )
231 if( xFilterContainer
.is() )
233 uno::Any aPackedSet
;
234 uno::Sequence
< beans::PropertyValue
> lProps
;
236 uui::FilterNamePair aPair
;
240 aPackedSet
= xFilterContainer
->getByName( rRequest
.SelectedFilter
);
242 catch(const container::NoSuchElementException
&)
246 aPackedSet
>>= lProps
;
247 for( nStep
=0; nStep
<lProps
.getLength(); ++nStep
)
249 if( lProps
[nStep
].Name
.compareToAscii("UIName") == 0 )
251 ::rtl::OUString sTemp
;
252 lProps
[nStep
].Value
>>= sTemp
;
254 aPair
.sInternal
= rRequest
.SelectedFilter
;
255 lNames
.push_back( aPair
);
262 aPackedSet
= xFilterContainer
->getByName( rRequest
.DetectedFilter
);
264 catch(const container::NoSuchElementException
&)
268 aPackedSet
>>= lProps
;
269 for( nStep
=0; nStep
<lProps
.getLength(); ++nStep
)
271 if( lProps
[nStep
].Name
.compareToAscii("UIName") == 0 )
273 ::rtl::OUString sTemp
;
274 lProps
[nStep
].Value
>>= sTemp
;
276 aPair
.sInternal
= rRequest
.DetectedFilter
;
277 lNames
.push_back( aPair
);
283 if( xAbort
.is() && xFilterTransport
.is() )
285 if( lNames
.size() < 1 )
291 rtl::OUString sFilter
;
292 executeFilterDialog( pParent
,
297 if( !sFilter
.isEmpty() )
299 xFilterTransport
->setFilter( sFilter
);
300 xFilterTransport
->select();
309 handleFilterOptionsRequest_(
310 uno::Reference
< lang::XMultiServiceFactory
> const & xServiceFactory
,
311 document::FilterOptionsRequest
const & rRequest
,
312 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
314 SAL_THROW((uno::RuntimeException
))
316 uno::Reference
< task::XInteractionAbort
> xAbort
;
317 uno::Reference
< document::XInteractionFilterOptions
> xFilterOptions
;
318 getContinuations(rContinuations
, &xAbort
, &xFilterOptions
);
320 uno::Reference
< container::XNameAccess
> xFilterCFG
;
323 xFilterCFG
.set( xServiceFactory
->createInstance(
324 ::rtl::OUString( "com.sun.star.document.FilterFactory" ) ),
327 catch ( uno::Exception
const & )
331 if( xFilterCFG
.is() && rRequest
.rProperties
.getLength() )
335 ::rtl::OUString aFilterName
;
336 sal_Int32 nPropCount
= rRequest
.rProperties
.getLength();
337 for( sal_Int32 ind
= 0; ind
< nPropCount
; ++ind
)
339 if( rRequest
.rProperties
[ind
].Name
.equals(
340 ::rtl::OUString("FilterName")) )
342 rRequest
.rProperties
[ind
].Value
>>= aFilterName
;
347 uno::Sequence
< beans::PropertyValue
> aProps
;
348 if ( xFilterCFG
->getByName( aFilterName
) >>= aProps
)
350 sal_Int32 nPropertyCount
= aProps
.getLength();
351 for( sal_Int32 nProperty
=0;
352 nProperty
< nPropertyCount
;
354 if( aProps
[nProperty
].Name
.equals(
355 ::rtl::OUString("UIComponent")) )
357 ::rtl::OUString aServiceName
;
358 aProps
[nProperty
].Value
>>= aServiceName
;
359 if( !aServiceName
.isEmpty() )
362 ui::dialogs::XExecutableDialog
> xFilterDialog(
363 xServiceFactory
->createInstance(
366 uno::Reference
< beans::XPropertyAccess
>
367 xFilterProperties( xFilterDialog
,
370 if( xFilterDialog
.is() && xFilterProperties
.is() )
373 document::XImporter
> xImporter(
374 xFilterDialog
, uno::UNO_QUERY
);
376 xImporter
->setTargetDocument(
377 uno::Reference
< lang::XComponent
>(
378 rRequest
.rModel
, uno::UNO_QUERY
) );
380 xFilterProperties
->setPropertyValues(
381 rRequest
.rProperties
);
383 if( xFilterDialog
->execute() )
385 xFilterOptions
->setFilterOptions(
386 xFilterProperties
->getPropertyValues() );
387 xFilterOptions
->select();
396 catch( container::NoSuchElementException
& )
398 // the filter name is unknown
400 catch( uno::Exception
& )
411 UUIInteractionHelper::handleNoSuchFilterRequest(
412 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
413 SAL_THROW((uno::RuntimeException
))
415 uno::Any
aAnyRequest(rRequest
->getRequest());
417 document::NoSuchFilterRequest aNoSuchFilterRequest
;
418 if (aAnyRequest
>>= aNoSuchFilterRequest
)
420 handleNoSuchFilterRequest_(getParentProperty(),
422 aNoSuchFilterRequest
,
423 rRequest
->getContinuations());
430 UUIInteractionHelper::handleAmbigousFilterRequest(
431 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
432 SAL_THROW((uno::RuntimeException
))
434 uno::Any
aAnyRequest(rRequest
->getRequest());
436 document::AmbigousFilterRequest aAmbigousFilterRequest
;
437 if (aAnyRequest
>>= aAmbigousFilterRequest
)
439 handleAmbigousFilterRequest_(getParentProperty(),
441 aAmbigousFilterRequest
,
442 rRequest
->getContinuations());
449 UUIInteractionHelper::handleFilterOptionsRequest(
450 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
451 SAL_THROW((uno::RuntimeException
))
453 uno::Any
aAnyRequest(rRequest
->getRequest());
455 document::FilterOptionsRequest aFilterOptionsRequest
;
456 if (aAnyRequest
>>= aFilterOptionsRequest
)
458 handleFilterOptionsRequest_(m_xServiceFactory
,
459 aFilterOptionsRequest
,
460 rRequest
->getContinuations());
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */