1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/beans/XPropertyAccess.hpp>
#include <com/sun/star/container/XContainerQuery.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/FilterOptionsRequest.hpp>
#include <com/sun/star/document/NoSuchFilterRequest.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XInteractionFilterOptions.hpp>
#include <com/sun/star/document/XInteractionFilterSelect.hpp>
#include <com/sun/star/task/XInteractionAbort.hpp>
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
#include <comphelper/propertysequence.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <vcl/svapp.hxx>
#include "getcontinuations.hxx"
#include "fltdlg.hxx"
#include "iahndl.hxx"
using namespace com::sun::star;
namespace {
void
executeFilterDialog(
weld::Window* pParent ,
OUString const & rURL ,
uui::FilterNameList const & rFilters,
OUString & rFilter )
{
SolarMutexGuard aGuard;
uui::FilterDialog aDialog(pParent);
aDialog.SetURL(rURL);
aDialog.ChangeFilters(&rFilters);
uui::FilterNameListPtr pSelected = rFilters.end();
if (aDialog.AskForFilter(pSelected))
{
rFilter = pSelected->sInternal;
}
}
void
handleNoSuchFilterRequest_(
weld::Window* pParent,
uno::Reference< uno::XComponentContext > const & xContext,
document::NoSuchFilterRequest const & rRequest,
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
rContinuations )
{
uno::Reference< task::XInteractionAbort > xAbort;
uno::Reference< document::XInteractionFilterSelect > xFilterTransport;
getContinuations(rContinuations, &xAbort, &xFilterTransport);
// check necessary resources - if they don't exist - abort or
// break this operation
if (!xAbort.is())
return;
if (!xFilterTransport.is())
{
xAbort->select();
return;
}
uno::Reference< container::XContainerQuery > xFilterContainer;
try
{
xFilterContainer.set( xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.FilterFactory", xContext ),
uno::UNO_QUERY );
}
catch ( uno::Exception const & )
{
}
if (!xFilterContainer.is())
{
xAbort->select();
return;
}
uui::FilterNameList lNames;
// Note: We look for all filters here which match the following criteria:
// - they are import filters as minimum (of course they can
// support export too)
// - we don't show any filter which are flagged as "don't show it
// at the UI" or "they are not installed"
// - we ignore filters, which have not set any valid
// DocumentService (e.g. our pure graphic filters)
// - we show it sorted by her UIName's
// - We don't use the order flag or prefer default filters.
// (Because this list shows all filters and the user should
// find his filter very easy by his UIName ...)
// - We use "_query_all" here ... but we filter graphic filters
// out by using DocumentService property later!
uno::Reference< container::XEnumeration > xFilters
= xFilterContainer->createSubSetEnumerationByQuery(
"_query_all:sort_prop=uiname:iflags=1:eflags=143360");
while (xFilters->hasMoreElements())
{
try
{
::comphelper::SequenceAsHashMap lProps(xFilters->nextElement());
uui::FilterNamePair aPair;
aPair.sInternal = lProps.getUnpackedValueOrDefault(
"Name", OUString());
aPair.sUI = lProps.getUnpackedValueOrDefault(
"UIName", OUString());
if ( aPair.sInternal.isEmpty() || aPair.sUI.isEmpty() )
{
continue;
}
lNames.push_back( aPair );
}
catch(const uno::RuntimeException&)
{
throw;
}
catch(const uno::Exception&)
{
continue;
}
}
// no list available for showing
// -> abort operation
if (lNames.empty())
{
xAbort->select();
return;
}
// let the user select the right filter
OUString sSelectedFilter;
executeFilterDialog( pParent,
rRequest.URL,
lNames,
sSelectedFilter );
// If he doesn't select anyone
// -> abort operation
if (sSelectedFilter.isEmpty())
{
xAbort->select();
return;
}
// otherwise set it for return
xFilterTransport->setFilter( sSelectedFilter );
xFilterTransport->select();
}
void
handleFilterOptionsRequest_(
uno::Reference<awt::XWindow> const & rWindow,
uno::Reference< uno::XComponentContext > const & xContext,
document::FilterOptionsRequest const & rRequest,
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
rContinuations)
{
uno::Reference< task::XInteractionAbort > xAbort;
uno::Reference< document::XInteractionFilterOptions > xFilterOptions;
getContinuations(rContinuations, &xAbort, &xFilterOptions);
uno::Reference< container::XNameAccess > xFilterCFG;
try
{
xFilterCFG.set( xContext->getServiceManager()->createInstanceWithContext(
"com.sun.star.document.FilterFactory", xContext ),
uno::UNO_QUERY );
}
catch ( uno::Exception const & )
{
}
if( xFilterCFG.is() && rRequest.rProperties.hasElements() )
{
try
{
OUString aFilterName;
auto pProperty = std::find_if(rRequest.rProperties.begin(), rRequest.rProperties.end(),
[](const beans::PropertyValue& rProp) { return rProp.Name == "FilterName"; });
if (pProperty != rRequest.rProperties.end())
{
pProperty->Value >>= aFilterName;
}
uno::Sequence < beans::PropertyValue > aProps;
if ( xFilterCFG->getByName( aFilterName ) >>= aProps )
{
auto pProp = std::find_if(aProps.begin(), aProps.end(),
[](const beans::PropertyValue& rProp) { return rProp.Name == "UIComponent"; });
if (pProp != aProps.end())
{
OUString aServiceName;
pProp->Value >>= aServiceName;
if( !aServiceName.isEmpty() )
{
uno::Sequence<uno::Any> aDialogArgs(comphelper::InitAnyPropertySequence(
{
{"ParentWindow", uno::Any(rWindow)},
}));
uno::Reference<
ui::dialogs::XExecutableDialog > xFilterDialog(
xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
aServiceName, aDialogArgs, xContext ),
uno::UNO_QUERY );
uno::Reference< beans::XPropertyAccess >
xFilterProperties( xFilterDialog,
uno::UNO_QUERY );
if( xFilterDialog.is() && xFilterProperties.is() )
{
uno::Reference<
document::XImporter > xImporter(
xFilterDialog, uno::UNO_QUERY );
if( xImporter.is() )
xImporter->setTargetDocument( rRequest.rModel );
xFilterProperties->setPropertyValues(
rRequest.rProperties );
if( xFilterDialog->execute() )
{
xFilterOptions->setFilterOptions(
xFilterProperties->getPropertyValues() );
xFilterOptions->select();
return;
}
}
}
}
}
}
catch( container::NoSuchElementException& )
{
// the filter name is unknown
}
catch( uno::Exception& )
{
}
}
xAbort->select();
}
} // namespace
bool
UUIInteractionHelper::handleNoSuchFilterRequest(
uno::Reference< task::XInteractionRequest > const & rRequest)
{
uno::Any aAnyRequest(rRequest->getRequest());
document::NoSuchFilterRequest aNoSuchFilterRequest;
if (aAnyRequest >>= aNoSuchFilterRequest)<--- Variable 'aAnyRequest' is assigned a value that is never used.
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleNoSuchFilterRequest_(Application::GetFrameWeld(xParent),
m_xContext,
aNoSuchFilterRequest,
rRequest->getContinuations());
return true;
}
return false;
}
bool
UUIInteractionHelper::handleFilterOptionsRequest(
uno::Reference< task::XInteractionRequest > const & rRequest)
{
uno::Any aAnyRequest(rRequest->getRequest());
document::FilterOptionsRequest aFilterOptionsRequest;
if (aAnyRequest >>= aFilterOptionsRequest)<--- Variable 'aAnyRequest' is assigned a value that is never used.
{
handleFilterOptionsRequest_(getParentXWindow(),
m_xContext,
aFilterOptionsRequest,
rRequest->getContinuations());
return true;
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|