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 <com/sun/star/beans/XPropertyAccess.hpp>
21 #include <com/sun/star/container/XContainerQuery.hpp>
22 #include <com/sun/star/container/XNameContainer.hpp>
23 #include <com/sun/star/document/FilterOptionsRequest.hpp>
24 #include <com/sun/star/document/NoSuchFilterRequest.hpp>
25 #include <com/sun/star/document/XImporter.hpp>
26 #include <com/sun/star/document/XInteractionFilterOptions.hpp>
27 #include <com/sun/star/document/XInteractionFilterSelect.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <com/sun/star/task/XInteractionAbort.hpp>
30 #include <com/sun/star/task/XInteractionRequest.hpp>
31 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
33 #include <comphelper/propertysequence.hxx>
34 #include <comphelper/sequenceashashmap.hxx>
35 #include <vcl/svapp.hxx>
37 #include "getcontinuations.hxx"
42 using namespace com::sun::star
;
48 weld::Window
* pParent
,
49 OUString
const & rURL
,
50 uui::FilterNameList
const & rFilters
,
53 SolarMutexGuard aGuard
;
55 uui::FilterDialog
aDialog(pParent
);
58 aDialog
.ChangeFilters(&rFilters
);
60 uui::FilterNameListPtr pSelected
= rFilters
.end();
61 if (aDialog
.AskForFilter(pSelected
))
63 rFilter
= pSelected
->sInternal
;
68 handleNoSuchFilterRequest_(
69 weld::Window
* pParent
,
70 uno::Reference
< uno::XComponentContext
> const & xContext
,
71 document::NoSuchFilterRequest
const & rRequest
,
72 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
75 uno::Reference
< task::XInteractionAbort
> xAbort
;
76 uno::Reference
< document::XInteractionFilterSelect
> xFilterTransport
;
77 getContinuations(rContinuations
, &xAbort
, &xFilterTransport
);
79 // check necessary resources - if they don't exist - abort or
80 // break this operation
84 if (!xFilterTransport
.is())
90 uno::Reference
< container::XContainerQuery
> xFilterContainer
;
93 xFilterContainer
.set( xContext
->getServiceManager()->createInstanceWithContext(
94 "com.sun.star.document.FilterFactory", xContext
),
97 catch ( uno::Exception
const & )
101 if (!xFilterContainer
.is())
107 uui::FilterNameList lNames
;
109 // Note: We look for all filters here which match the following criteria:
110 // - they are import filters as minimum (of course they can
111 // support export too)
112 // - we don't show any filter which are flagged as "don't show it
113 // at the UI" or "they are not installed"
114 // - we ignore filters, which have not set any valid
115 // DocumentService (e.g. our pure graphic filters)
116 // - we show it sorted by her UIName's
117 // - We don't use the order flag or prefer default filters.
118 // (Because this list shows all filters and the user should
119 // find his filter very easy by his UIName ...)
120 // - We use "_query_all" here ... but we filter graphic filters
121 // out by using DocumentService property later!
122 uno::Reference
< container::XEnumeration
> xFilters
123 = xFilterContainer
->createSubSetEnumerationByQuery(
124 "_query_all:sort_prop=uiname:iflags=1:eflags=143360");
125 while (xFilters
->hasMoreElements())
129 ::comphelper::SequenceAsHashMap
lProps(xFilters
->nextElement());
130 uui::FilterNamePair aPair
;
132 aPair
.sInternal
= lProps
.getUnpackedValueOrDefault(
134 aPair
.sUI
= lProps
.getUnpackedValueOrDefault(
135 "UIName", OUString());
136 if ( aPair
.sInternal
.isEmpty() || aPair
.sUI
.isEmpty() )
140 lNames
.push_back( aPair
);
142 catch(const uno::RuntimeException
&)
146 catch(const uno::Exception
&)
152 // no list available for showing
153 // -> abort operation
160 // let the user select the right filter
161 OUString sSelectedFilter
;
162 executeFilterDialog( pParent
,
167 // If he doesn't select anyone
168 // -> abort operation
169 if (sSelectedFilter
.isEmpty())
175 // otherwise set it for return
176 xFilterTransport
->setFilter( sSelectedFilter
);
177 xFilterTransport
->select();
181 handleFilterOptionsRequest_(
182 uno::Reference
<awt::XWindow
> const & rWindow
,
183 uno::Reference
< uno::XComponentContext
> const & xContext
,
184 document::FilterOptionsRequest
const & rRequest
,
185 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
188 uno::Reference
< task::XInteractionAbort
> xAbort
;
189 uno::Reference
< document::XInteractionFilterOptions
> xFilterOptions
;
190 getContinuations(rContinuations
, &xAbort
, &xFilterOptions
);
192 uno::Reference
< container::XNameAccess
> xFilterCFG
;
195 xFilterCFG
.set( xContext
->getServiceManager()->createInstanceWithContext(
196 "com.sun.star.document.FilterFactory", xContext
),
199 catch ( uno::Exception
const & )
203 if( xFilterCFG
.is() && rRequest
.rProperties
.getLength() )
207 OUString aFilterName
;
208 sal_Int32 nPropCount
= rRequest
.rProperties
.getLength();
209 for( sal_Int32 ind
= 0; ind
< nPropCount
; ++ind
)
211 if( rRequest
.rProperties
[ind
].Name
== "FilterName" )
213 rRequest
.rProperties
[ind
].Value
>>= aFilterName
;
218 uno::Sequence
< beans::PropertyValue
> aProps
;
219 if ( xFilterCFG
->getByName( aFilterName
) >>= aProps
)
221 sal_Int32 nPropertyCount
= aProps
.getLength();
222 for( sal_Int32 nProperty
=0;
223 nProperty
< nPropertyCount
;
225 if( aProps
[nProperty
].Name
== "UIComponent" )
227 OUString aServiceName
;
228 aProps
[nProperty
].Value
>>= aServiceName
;
229 if( !aServiceName
.isEmpty() )
231 uno::Sequence
<uno::Any
> aDialogArgs(comphelper::InitAnyPropertySequence(
233 {"ParentWindow", uno::Any(rWindow
)},
237 ui::dialogs::XExecutableDialog
> xFilterDialog(
238 xContext
->getServiceManager()->createInstanceWithArgumentsAndContext(
239 aServiceName
, aDialogArgs
, xContext
),
242 uno::Reference
< beans::XPropertyAccess
>
243 xFilterProperties( xFilterDialog
,
246 if( xFilterDialog
.is() && xFilterProperties
.is() )
249 document::XImporter
> xImporter(
250 xFilterDialog
, uno::UNO_QUERY
);
252 xImporter
->setTargetDocument(
253 uno::Reference
< lang::XComponent
>(
254 rRequest
.rModel
, uno::UNO_QUERY
) );
256 xFilterProperties
->setPropertyValues(
257 rRequest
.rProperties
);
259 if( xFilterDialog
->execute() )
261 xFilterOptions
->setFilterOptions(
262 xFilterProperties
->getPropertyValues() );
263 xFilterOptions
->select();
272 catch( container::NoSuchElementException
& )
274 // the filter name is unknown
276 catch( uno::Exception
& )
287 UUIInteractionHelper::handleNoSuchFilterRequest(
288 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
290 uno::Any
aAnyRequest(rRequest
->getRequest());
292 document::NoSuchFilterRequest aNoSuchFilterRequest
;
293 if (aAnyRequest
>>= aNoSuchFilterRequest
)
295 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
296 handleNoSuchFilterRequest_(Application::GetFrameWeld(xParent
),
298 aNoSuchFilterRequest
,
299 rRequest
->getContinuations());
306 UUIInteractionHelper::handleFilterOptionsRequest(
307 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
309 uno::Any
aAnyRequest(rRequest
->getRequest());
311 document::FilterOptionsRequest aFilterOptionsRequest
;
312 if (aAnyRequest
>>= aFilterOptionsRequest
)
314 handleFilterOptionsRequest_(getParentXWindow(),
316 aFilterOptionsRequest
,
317 rRequest
->getContinuations());
324 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */