Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/dialog/filedlgimpl.hxx
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
#ifndef INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
20
#define INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
21
22
#include <sal/config.h>
23
24
#include <vector>
25
26
#include <vcl/timer.hxx>
27
#include <vcl/idle.hxx>
28
#include <vcl/graph.hxx>
29
#include <cppuhelper/implbase.hxx>
30
#include <com/sun/star/beans/StringPair.hpp>
31
#include <com/sun/star/container/XNameAccess.hpp>
32
#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp>
33
#include <com/sun/star/ui/dialogs/XDialogClosedListener.hpp>
34
#include <unotools/saveopt.hxx>
35
#include <sfx2/fcontnr.hxx>
36
#include <sfx2/filedlghelper.hxx>
37
38
class SfxFilterMatcher;
39
class GraphicFilter;
40
41
namespace sfx2
42
{
43
    class FileDialogHelper_Impl :
44
        public ::cppu::WeakImplHelper<
45
            css::ui::dialogs::XFilePickerListener,
46
            css::ui::dialogs::XDialogClosedListener >
47
    {
48
        friend class FileDialogHelper;
49
50
        css::uno::Reference < css::ui::dialogs::XFilePicker3 > mxFileDlg;
51
        css::uno::Reference < css::container::XNameAccess >   mxFilterCFG;
52
53
        std::vector< css::beans::StringPair >   maFilters;
54
55
        SfxFilterMatcher*           mpMatcher;
56
        std::unique_ptr<GraphicFilter> mpGraphicFilter;
57
        FileDialogHelper*           mpAntiImpl;
58
        weld::Window*               mpFrameWeld;
59
60
        OUString             maPath;
61
        OUString             maFileName;
62
        OUString             maCurFilter;
63
        OUString             maSelectFilter;
64
        OUString             maButtonLabel;
65
        OUString             msPreselectedDir;
66
67
        Idle                        maPreviewIdle;
68
        Graphic                     maGraphic;
69
70
        const short                 m_nDialogType;
71
72
        SfxFilterFlags              m_nMustFlags;
73
        SfxFilterFlags              m_nDontFlags;
74
75
        FileDialogHelper::Context   meContext;
76
77
        bool                    mbHasPassword           : 1;  // checkbox is visible
78
        bool                    mbIsPwdEnabled          : 1;  // password checkbox is not grayed out
79
        bool                    mbIsGpgEncrEnabled      : 1;  // GPG checkbox is not grayed out
80
        bool                    m_bHaveFilterOptions    : 1;
81
        bool                    mbHasVersions           : 1;
82
        bool                    mbHasAutoExt            : 1;
83
        bool                    mbHasPreview            : 1;
84
        bool                    mbShowPreview           : 1;
85
        bool                    mbIsSaveDlg             : 1;
86
        bool                    mbExport                : 1;
87
88
        bool                    mbDeleteMatcher         : 1;
89
        bool                    mbInsert                : 1;
90
        bool                    mbSystemPicker          : 1;
91
        bool                    mbAsyncPicker           : 1;
92
        bool                    mbPwdCheckBoxState      : 1;
93
        bool                    mbGpgCheckBoxState      : 1;
94
        bool                    mbSelection             : 1;
95
        bool                    mbSelectionEnabled      : 1;
96
        bool                    mbHasSelectionBox       : 1;
97
        bool                    mbSelectionFltrEnabled  : 1;
98
        bool                    mbHasSignByDefault      : 1;
99
100
    private:
101
        void                    addFilters( const OUString& rFactory,
102
                                            SfxFilterFlags nMust,
103
                                            SfxFilterFlags nDont );
104
        void                    addFilter( const OUString& rFilterName,
105
                                           const OUString& rExtension );
106
        void                    addGraphicFilter();
107
        void                    enablePasswordBox( bool bInit );
108
        void                    enableGpgEncrBox( bool bInit );
109
        void                    updateFilterOptionsBox();
110
        void                    updateExportButton();
111
        void                    updateSelectionBox();
112
        void                    updateSignByDefault();
113
        void                    updateVersions();
114
        void                    updatePreviewState( bool _bUpdatePreviewWindow );
115
        void                    dispose();
116
117
        void                    loadConfig();
118
        void                    saveConfig();
119
120
        std::shared_ptr<const SfxFilter>        getCurrentSfxFilter();
121
        bool                updateExtendedControl( sal_Int16 _nExtendedControlId, bool _bEnable );
122
123
        ErrCode                 getGraphic( const OUString& rURL, Graphic& rGraphic );
124
        void                    setDefaultValues();
125
126
        void                    preExecute();
127
        void                    postExecute( sal_Int16 _nResult );
128
        sal_Int16               implDoExecute();
129
        void                    implStartExecute();
130
131
        void                    setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId );
132
133
        bool                    CheckFilterOptionsCapability( const std::shared_ptr<const SfxFilter>& _pFilter );
134
135
        bool                    isInOpenMode() const;
136
        OUString                getCurrentFilterUIName() const;
137
138
        void                    LoadLastUsedFilter( const OUString& _rContextIdentifier );
139
        void                    SaveLastUsedFilter();
140
141
        void                    implInitializeFileName( );
142
143
        void                    verifyPath( );
144
145
        DECL_LINK( TimeOutHdl_Impl, Timer *, void);
146
147
    public:
148
        // XFilePickerListener methods
149
        virtual void SAL_CALL               fileSelectionChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
150
        virtual void SAL_CALL               directoryChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
151
        virtual OUString SAL_CALL           helpRequested( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
152
        virtual void SAL_CALL               controlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent ) override;
153
        virtual void SAL_CALL               dialogSizeChanged() override;
154
155
        // XDialogClosedListener methods
156
        virtual void SAL_CALL               dialogClosed( const css::ui::dialogs::DialogClosedEvent& _rEvent ) override;
157
158
        // XEventListener methods
159
        virtual void SAL_CALL       disposing( const css::lang::EventObject& Source ) override;
160
161
        // handle XFilePickerListener events
162
        void                    handleFileSelectionChanged();
163
        void                    handleDirectoryChanged();
164
        static OUString         handleHelpRequested( const css::ui::dialogs::FilePickerEvent& aEvent );
165
        void                    handleControlStateChanged( const css::ui::dialogs::FilePickerEvent& aEvent );
166
        void                    handleDialogSizeChanged();
167
168
        // Own methods
169
                                FileDialogHelper_Impl(
170
                                    FileDialogHelper* _pAntiImpl,
171
                                    const sal_Int16 nDialogType,
172
                                    FileDialogFlags nFlags,
173
                                    sal_Int16 nDialog,
174
                                    weld::Window* pFrameWeld,
175
                                    const OUString& sPreselectedDir = OUString(),
176
                                    const css::uno::Sequence< OUString >&   rDenyList = css::uno::Sequence< OUString >()
177
                                );
178
        virtual                 ~FileDialogHelper_Impl() override;
179
180
        ErrCode                 execute( css::uno::Sequence<OUString>& rpURLList,
181
                                         std::optional<SfxAllItemSet>& rpSet,
182
                                         OUString&       rFilter,
183
                                         SignatureState nScriptingSignatureState);
184
        ErrCode                 execute();
185
186
        void                    setFilter( const OUString& rFilter );
187
188
        /** sets the directory which should be browsed
189
190
            <p>If the given path does not point to a valid (existent and accessible) folder, the request
191
            is silently dropped</p>
192
        */
193
        void                    displayFolder( const OUString& rPath );
194
        void                    setFileName( const OUString& _rFile );
195
196
        OUString                getPath() const;
197
        OUString                getFilter() const;
198
        void                    getRealFilter( OUString& _rFilter ) const;
199
200
        ErrCode                 getGraphic( Graphic& rGraphic );
201
        void                    createMatcher( const OUString& rFactory );
202
203
        bool                    isShowFilterExtensionEnabled() const;
204
        void                    addFilterPair( const OUString& rFilter,
205
                                               const OUString& rFilterWithExtension );
206
        OUString                getFilterName( std::u16string_view rFilterWithExtension ) const;
207
        OUString                getFilterWithExtension( std::u16string_view rFilter ) const;
208
209
        void                    SetContext( FileDialogHelper::Context _eNewContext );
210
        OUString                getInitPath( std::u16string_view _rFallback, const sal_Int32 _nFallbackToken );
211
212
0
        bool             isAsyncFilePicker() const { return mbAsyncPicker; }
213
0
        bool             isPasswordEnabled() const { return mbIsPwdEnabled; }
214
215
        css::uno::Reference<css::awt::XWindow> GetFrameInterface();
216
    };
217
}   // end of namespace sfx2
218
219
#endif // INCLUDED_SFX2_SOURCE_DIALOG_FILEDLGIMPL_HXX
220
221
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */