Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/fwe/dispatch/interaction.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <comphelper/interaction.hxx>
21
#include <framework/interaction.hxx>
22
#include <com/sun/star/document/XInteractionFilterSelect.hpp>
23
#include <com/sun/star/document/NoSuchFilterRequest.hpp>
24
#include <utility>
25
26
using namespace ::com::sun::star;
27
28
namespace framework{
29
30
namespace {
31
32
/*-************************************************************************************************************
33
    @short          declaration of special continuation for filter selection
34
    @descr          Sometimes filter detection during loading document failed. Then we need a possibility
35
                    to ask user for his decision. These continuation transport selected filter by user to
36
                    code user of interaction.
37
38
    @attention      This implementation could be used one times only. We don't support a resettable continuation yet!
39
                    Why? Normally interaction should show a filter selection dialog and ask user for his decision.
40
                    He can select any filter - then instances of these class will be called by handler... or user
41
                    close dialog without any selection. Then another continuation should be selected by handler to
42
                    abort continuations... Retrying isn't very useful here... I think.
43
44
    @implements     XInteractionFilterSelect
45
46
    @base           ImplInheritanceHelper
47
                    ContinuationBase
48
49
    @devstatus      ready to use
50
    @threadsafe     no (used on once position only!)
51
*//*-*************************************************************************************************************/
52
class ContinuationFilterSelect : public comphelper::OInteraction< css::document::XInteractionFilterSelect >
53
{
54
    // c++ interface
55
    public:
56
        ContinuationFilterSelect();
57
58
    // uno interface
59
    public:
60
        virtual void            SAL_CALL setFilter( const OUString& sFilter ) override;
61
        virtual OUString SAL_CALL getFilter(                                ) override;
62
63
    // member
64
    private:
65
        OUString m_sFilter;
66
67
};  // class ContinuationFilterSelect
68
69
}
70
71
// initialize continuation with right start values
72
73
ContinuationFilterSelect::ContinuationFilterSelect()
74
0
{
75
0
}
76
77
// handler should use it after selection to set user specified filter for transport
78
79
void SAL_CALL ContinuationFilterSelect::setFilter( const OUString& sFilter )
80
0
{
81
0
    m_sFilter = sFilter;
82
0
}
83
84
// read access to transported filter
85
86
OUString SAL_CALL ContinuationFilterSelect::getFilter()
87
0
{
88
0
    return m_sFilter;
89
0
}
90
91
class RequestFilterSelect_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
92
{
93
public:
94
    explicit RequestFilterSelect_Impl(const OUString& rURL);
95
    bool     isAbort  () const;
96
    OUString getFilter() const;
97
98
public:
99
    virtual css::uno::Any SAL_CALL getRequest() override;
100
    virtual css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL getContinuations() override;
101
102
private:
103
    css::uno::Any                                                                       m_aRequest;
104
    rtl::Reference<comphelper::OInteractionAbort>                                       m_xAbort;
105
    rtl::Reference<ContinuationFilterSelect>                                            m_xFilter;
106
};
107
108
// initialize instance with all necessary information
109
// We use it without any further checks on our member then ...!
110
111
RequestFilterSelect_Impl::RequestFilterSelect_Impl( const OUString& sURL )
112
0
{
113
0
    css::uno::Reference< css::uno::XInterface > temp2;
114
0
    css::document::NoSuchFilterRequest aFilterRequest( OUString(),
115
0
                                                       temp2                            ,
116
0
                                                       sURL                                          );
117
0
    m_aRequest <<= aFilterRequest;
118
119
0
    m_xAbort  = new comphelper::OInteractionAbort;
120
0
    m_xFilter = new ContinuationFilterSelect;
121
0
}
122
123
// return abort state of interaction
124
// If it is true, return value of method "getFilter()" will be unspecified then!
125
126
bool RequestFilterSelect_Impl::isAbort() const
127
0
{
128
0
    return m_xAbort->wasSelected();
129
0
}
130
131
// return user selected filter
132
// Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
133
134
OUString RequestFilterSelect_Impl::getFilter() const
135
0
{
136
0
    return m_xFilter->getFilter();
137
0
}
138
139
// handler call it to get type of request
140
// Is hard coded to "please select filter" here. see ctor for further information.
141
142
css::uno::Any SAL_CALL RequestFilterSelect_Impl::getRequest()
143
0
{
144
0
    return m_aRequest;
145
0
}
146
147
// handler call it to get possible continuations
148
// We support "abort/select_filter" only here.
149
// After interaction we support read access on these continuations on our c++ interface to
150
// return user decision.
151
152
css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > SAL_CALL RequestFilterSelect_Impl::getContinuations()
153
0
{
154
0
    return { m_xAbort, m_xFilter };
155
0
}
156
157
RequestFilterSelect::RequestFilterSelect( const OUString& sURL )
158
0
    : mxImpl(new RequestFilterSelect_Impl( sURL ))
159
0
{
160
0
}
161
162
RequestFilterSelect::~RequestFilterSelect()
163
0
{
164
0
}
165
166
// return abort state of interaction
167
// If it is true, return value of method "getFilter()" will be unspecified then!
168
169
bool RequestFilterSelect::isAbort() const
170
0
{
171
0
    return mxImpl->isAbort();
172
0
}
173
174
// return user selected filter
175
// Return value valid for non aborted interaction only. Please check "isAbort()" before you call these only!
176
177
OUString RequestFilterSelect::getFilter() const
178
0
{
179
0
    return mxImpl->getFilter();
180
0
}
181
182
uno::Reference < task::XInteractionRequest > RequestFilterSelect::GetRequest() const
183
0
{
184
0
    return mxImpl;
185
0
}
186
187
namespace {
188
189
class InteractionRequest_Impl : public ::cppu::WeakImplHelper< css::task::XInteractionRequest >
190
{
191
    uno::Any m_aRequest;
192
    uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > m_lContinuations;
193
194
public:
195
    InteractionRequest_Impl( css::uno::Any  aRequest,
196
        const css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > >& lContinuations )
197
0
        : m_aRequest(std::move(aRequest)), m_lContinuations(lContinuations)
198
0
    {
199
0
    }
200
201
    virtual uno::Any SAL_CALL getRequest() override;
202
    virtual uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL getContinuations() override;
203
};
204
205
}
206
207
uno::Any SAL_CALL InteractionRequest_Impl::getRequest()
208
0
{
209
0
    return m_aRequest;
210
0
}
211
212
uno::Sequence< uno::Reference< task::XInteractionContinuation > > SAL_CALL InteractionRequest_Impl::getContinuations()
213
0
{
214
0
    return m_lContinuations;
215
0
}
216
217
uno::Reference < task::XInteractionRequest > InteractionRequest::CreateRequest(
218
    const uno::Any& aRequest, const uno::Sequence< uno::Reference< task::XInteractionContinuation > >& lContinuations )
219
0
{
220
0
    return new InteractionRequest_Impl( aRequest, lContinuations );
221
0
}
222
223
}       //  namespace framework
224
225
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */