Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / fpicker / source / office / iodlg.hxx
blob2dc3df9ec9e58101f5875e63927ce07b643c8d5b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
22 #include <memory>
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>
35 #include <set>
38 class SvtFileView;
39 class SvtFileDialogFilter_Impl;
40 class SvtExpFileDlg_Impl;
41 class URLBox;
43 enum class AdjustFilterFlags {
44 NONE = 0x0000,
45 NonEmpty = 0x0001,
46 Changed = 0x0002,
47 UserFilter = 0x0004,
49 namespace o3tl {
50 template<> struct typed_flags<AdjustFilterFlags> : is_typed_flags<AdjustFilterFlags, 0x0007> {};
54 class SvtFileDialog final : public SvtFileDialog_Base
56 private:
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;
68 Size m_aPreviewSize;
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;
80 bool m_bHasFilename;
81 css::uno::Reference < css::uno::XComponentContext >
82 m_xContext;
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
103 @param _rFilter
104 the wildcard pattern to look for in the filter list
105 @param _bMultiExt
106 allow for filters with more than one extension pattern
107 @param _rFilterChanged
108 set to <TRUE/> if the filter changed
109 @return
110 the filter which has been found
112 SvtFileDialogFilter_Impl* FindFilter_Impl( const OUString& _rFilter,
113 bool _bMultiExt,
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 );
132 OUString m_aPath;
133 OUString m_aDefExt;
135 /** enables or disables the complete UI of the file picker, with only offering a
136 cancel button
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;
154 public:
155 SvtFileDialog( weld::Window* pParent, PickerFlags nBits );
156 virtual ~SvtFileDialog() override;
158 virtual short run() override;
160 void FileSelect();
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;
172 void AddFilterGroup(
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;
186 void InitSize();
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 );
208 // inline
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 );
221 private:
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
239 void executeAsync(
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
246 necessary.
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
254 of the used filter.
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 )
268 m_aPath = rNewURL;
272 inline void SvtFileDialog::SetHasFilename( bool bHasFilename )
274 m_bHasFilename = bHasFilename;
278 inline const OUString& SvtFileDialog::GetPath()
280 return m_aPath;
284 inline void SvtFileDialog::SetDefaultExt( const OUString& rExt )
286 m_aDefExt = rExt;
289 inline void SvtFileDialog::EraseDefaultExt( sal_Int32 _nIndex )
291 m_aDefExt = m_aDefExt.copy( 0, _nIndex );
294 inline const OUString& SvtFileDialog::GetDefaultExt() const
296 return m_aDefExt;
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: */