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 .
19 #ifndef INCLUDED_FPICKER_SOURCE_OFFICE_IODLG_HXX
20 #define INCLUDED_FPICKER_SOURCE_OFFICE_IODLG_HXX
23 #include <com/sun/star/beans/StringPair.hpp>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <com/sun/star/ucb/IOErrorCode.hpp>
28 #include <unotools/confignode.hxx>
29 #include "asyncfilepicker.hxx"
30 #include "fpsmartcontent.hxx"
31 #include "fpdialogbase.hxx"
32 #include <o3tl/typed_flags_set.hxx>
33 #include <vcl/timer.hxx>
39 class SvtFileDialogFilter_Impl
;
40 class SvtExpFileDlg_Impl
;
43 enum class AdjustFilterFlags
{
50 template<> struct typed_flags
<AdjustFilterFlags
> : is_typed_flags
<AdjustFilterFlags
, 0x0007> {};
54 class SvtFileDialog final
: public SvtFileDialog_Base
57 std::unique_ptr
<weld::CheckButton
> m_xCbReadOnly
;
58 std::unique_ptr
<weld::CheckButton
> m_xCbLinkBox
;
59 std::unique_ptr
<weld::CheckButton
> m_xCbPreviewBox
;
60 std::unique_ptr
<weld::CheckButton
> m_xCbSelection
;
61 std::unique_ptr
<weld::Button
> m_xPbPlay
;
62 std::unique_ptr
<weld::Widget
> m_xPreviewFrame
;
63 std::unique_ptr
<weld::Image
> m_xPrevBmp
;
64 std::unique_ptr
<weld::Container
> m_xContainer
;
65 std::unique_ptr
<SvtFileView
> m_xFileView
;
66 ::svt::IFilePickerListener
* m_pFileNotifier
;
67 std::unique_ptr
<SvtExpFileDlg_Impl
> m_xImpl
;
69 PickerFlags m_nPickerFlags
;
70 bool m_bIsInExecute
: 1;
72 ::svt::SmartContent m_aContent
;
74 ::std::set
<weld::Widget
*> m_aDisabledControls
;
76 ::utl::OConfigurationNode m_aConfiguration
;
77 ::rtl::Reference
< ::svt::AsyncPickerAction
>
78 m_pCurrentAsyncAction
;
79 bool m_bInExecuteAsync
;
81 css::uno::Reference
< css::uno::XComponentContext
>
84 DECL_LINK( FilterSelectHdl_Impl
, weld::ComboBox
&, void );
85 DECL_LINK( FilterSelectTimerHdl_Impl
, Timer
*, void );
86 DECL_LINK( NewFolderHdl_Impl
, weld::Button
&, void );
87 DECL_LINK( OpenUrlHdl_Impl
, weld::ComboBox
&, bool );
88 DECL_LINK( OpenClickHdl_Impl
, weld::Button
&, void );
89 DECL_LINK( CancelHdl_Impl
, weld::Button
&, void );
90 DECL_LINK( FileNameGetFocusHdl_Impl
, weld::Widget
&, void );
91 DECL_LINK( FileNameModifiedHdl_Impl
, weld::ComboBox
&, void );
93 DECL_LINK( URLBoxModifiedHdl_Impl
, weld::ComboBox
&, bool );
94 DECL_LINK( ConnectToServerPressed_Hdl
, weld::Button
&, void );
96 DECL_LINK( AddPlacePressed_Hdl
, weld::Button
&, void );
97 DECL_LINK( RemovePlacePressed_Hdl
, weld::Button
&, void );
98 DECL_LINK( PreviewSizeAllocHdl
, const Size
&, void);
100 void OpenHdl_Impl(void const * pVoid
);
102 /** find a filter with the given wildcard
104 the wildcard pattern to look for in the filter list
106 allow for filters with more than one extension pattern
107 @param _rFilterChanged
108 set to <TRUE/> if the filter changed
110 the filter which has been found
112 SvtFileDialogFilter_Impl
* FindFilter_Impl( const OUString
& _rFilter
,
114 bool& _rFilterChanged
116 void ExecuteFilter();
117 void OpenMultiSelection_Impl();
118 void AddControls_Impl( );
120 DECL_LINK(SelectHdl_Impl
, SvtFileView
*, void);
121 DECL_LINK(DblClickHdl_Impl
, SvtFileView
*, bool);
122 DECL_LINK(EntrySelectHdl_Impl
, weld::ComboBox
&, void);
123 DECL_LINK(OpenDoneHdl_Impl
, SvtFileView
*, void);
124 DECL_LINK(AutoExtensionHdl_Impl
, weld::Button
&, void);
125 DECL_LINK(ClickHdl_Impl
, weld::Button
&, void);
126 DECL_LINK(PlayButtonHdl_Impl
, weld::Button
&, void);
127 DECL_LINK(SizeAllocHdl
, const Size
&, void);
129 // removes a filter with wildcards from the path and returns it
130 static bool IsolateFilterFromPath_Impl( OUString
& rPath
, OUString
& rFilter
);
135 /** enables or disables the complete UI of the file picker, with only offering a
138 This method preserves the "enabled" state of its controls in the following sense:
139 If you disable a certain control, then disable the dialog UI, then enable the dialog
140 UI, the control will still be disabled.
141 This is under the assumption that you'll use EnableControl. Direct access to the control
142 (such as pControl->Enable()) will break this.
144 void EnableUI( bool _bEnable
);
146 /** enables or disables a control
148 You are strongly encouraged to prefer this method over pControl->Enable( bEnable ). See
149 <member>EnableUI</member> for details.
151 void EnableControl(weld::Widget
* pControl
, bool bEnable
);
152 virtual bool PrepareExecute() override
;
155 SvtFileDialog( weld::Window
* pParent
, PickerFlags nBits
);
156 virtual ~SvtFileDialog() override
;
158 virtual short run() override
;
161 void FilterSelect() override
;
163 void SetBlackList( const css::uno::Sequence
< OUString
>& rBlackList
) override
;
164 const css::uno::Sequence
< OUString
>& GetBlackList() const override
;
165 void SetStandardDir( const OUString
& rStdDir
) override
;
166 const OUString
& GetStandardDir() const override
;
167 std::vector
<OUString
> GetPathList() const override
; // for MultiSelection
169 void AddFilter( const OUString
& rFilter
,
170 const OUString
& rType
) override
;
173 const OUString
& _rFilter
,
174 const css::uno::Sequence
< css::beans::StringPair
>& rFilters
) override
;
176 void SetCurFilter( const OUString
& rFilter
) override
;
177 OUString
GetCurFilter() const override
;
178 sal_uInt16
GetFilterCount() const;
179 const OUString
& GetFilterName( sal_uInt16 nPos
) const;
181 void PrevLevel_Impl();
182 void OpenURL_Impl( const OUString
& rURL
);
184 SvtFileView
* GetView() override
;
187 void UpdateControls( const OUString
& rURL
) override
;
188 void EnableAutocompletion( bool _bEnable
= true ) override
;
190 void SetFileCallback( ::svt::IFilePickerListener
*pNotifier
) override
{ m_pFileNotifier
= pNotifier
; }
192 sal_Int32
getAvailableWidth() override
;
193 sal_Int32
getAvailableHeight() override
;
194 void setImage( const css::uno::Any
& rImage
) override
;
195 bool getShowState() override
;
196 bool isAutoExtensionEnabled() const;
198 OUString
getCurrentFileText( ) const override
;
199 void setCurrentFileText( const OUString
& _rText
, bool _bSelectAll
= false ) override
;
201 void onAsyncOperationStarted() override
;
202 void onAsyncOperationFinished() override
;
204 void RemovablePlaceSelected(bool enable
= true);
206 static void displayIOException( const OUString
& _rURL
, css::ucb::IOErrorCode _eCode
);
209 inline void SetPath( const OUString
& rNewURL
) override
;
210 inline void SetHasFilename( bool bHasFilename
) override
;
211 inline const OUString
& GetPath() override
;
212 inline void SetDefaultExt( const OUString
& rExt
);
213 inline void EraseDefaultExt( sal_Int32 _nIndex
= 0 );
214 inline const OUString
& GetDefaultExt() const;
216 bool ContentIsFolder( const OUString
& rURL
) override
{ return m_aContent
.isFolder( rURL
) && m_aContent
.isValid(); }
217 bool ContentHasParentFolder( const OUString
& rURL
);
218 bool ContentCanMakeFolder( const OUString
& rURL
);
219 bool ContentGetTitle( const OUString
& rURL
, OUString
& rTitle
);
222 SvtFileDialogFilter_Impl
* implAddFilter( const OUString
& _rFilter
, const OUString
& _rType
);
224 /** updates m_xUserFilter with a new filter
225 <p>No checks for necessity are made.</p>
227 void createNewUserFilter( const OUString
& _rNewFilter
);
229 AdjustFilterFlags
adjustFilter( const OUString
& _rFilter
);
231 // IFilePickerController, needed by OControlAccess
232 virtual weld::Widget
* getControl( sal_Int16 nControlId
, bool bLabelControl
= false ) const override
;
233 virtual void enableControl( sal_Int16 _nControlId
, bool _bEnable
) override
;
234 virtual OUString
getCurFilter( ) const override
;
236 OUString
implGetInitialURL( const OUString
& _rPath
, const OUString
& _rFallback
);
238 /// executes a certain FileView action asynchronously
240 ::svt::AsyncPickerAction::Action _eAction
,
241 const OUString
& _rURL
,
242 const OUString
& _rFilter
245 /** helper function to check and append the default filter extension if
247 The function checks if the specified filename already contains one of
248 the valid extensions of the specified filter. If not the filter default
249 extension is appended to the filename.
251 @param _rFileName the filename which is checked and extended if necessary.
252 @param _rFilterDefaultExtension the default extension of the used filter.
253 @param _rFilterExtensions a list of one or more valid filter extensions
257 static void appendDefaultExtension(
258 OUString
& _rFileName
,
259 const OUString
& _rFilterDefaultExtension
,
260 const OUString
& _rFilterExtensions
);
262 void initDefaultPlaces( );
266 inline void SvtFileDialog::SetPath( const OUString
& rNewURL
)
272 inline void SvtFileDialog::SetHasFilename( bool bHasFilename
)
274 m_bHasFilename
= bHasFilename
;
278 inline const OUString
& SvtFileDialog::GetPath()
284 inline void SvtFileDialog::SetDefaultExt( const OUString
& rExt
)
289 inline void SvtFileDialog::EraseDefaultExt( sal_Int32 _nIndex
)
291 m_aDefExt
= m_aDefExt
.copy( 0, _nIndex
);
294 inline const OUString
& SvtFileDialog::GetDefaultExt() const
300 inline SvtFileView
* SvtFileDialog::GetView()
302 return m_xFileView
.get();
305 #endif // INCLUDED_FPICKER_SOURCE_OFFICE_IODLG_HXX
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */