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 .
22 #include <vclpluginapi.h>
24 #include <cppuhelper/compbase.hxx>
26 #include <com/sun/star/frame/XTerminateListener.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
30 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
31 #include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <osl/conditn.hxx>
35 #include <osl/mutex.hxx>
37 #include <QtCore/QObject>
38 #include <QtCore/QString>
39 #include <QtCore/QStringList>
40 #include <QtCore/QHash>
41 #include <QtWidgets/QFileDialog>
50 typedef ::cppu::WeakComponentImplHelper
<css::frame::XTerminateListener
, css::lang::XInitialization
,
51 css::lang::XServiceInfo
, css::ui::dialogs::XFilePicker3
,
52 css::ui::dialogs::XFilePickerControlAccess
,
53 css::ui::dialogs::XFolderPicker2
>
56 class VCLPLUG_QT5_PUBLIC Qt5FilePicker
: public QObject
, public Qt5FilePicker_Base
61 css::uno::Reference
<css::uno::XComponentContext
> m_context
;
63 css::uno::Reference
<css::ui::dialogs::XFilePickerListener
> m_xListener
;
65 osl::Mutex m_aHelperMutex
; ///< mutex used by the WeakComponentImplHelper
67 QStringList m_aNamedFilterList
; ///< to keep the original sequence
68 QHash
<QString
, QString
> m_aTitleToFilterMap
;
69 // to retrieve the filename extension for a given filter
70 QHash
<QString
, QString
> m_aNamedFilterToExtensionMap
;
71 QString m_aCurrentFilter
;
73 QGridLayout
* m_pLayout
; ///< layout for extra custom controls
74 QHash
<sal_Int16
, QWidget
*> m_aCustomWidgetsMap
; ///< map of SAL control ID's to widget
76 const bool m_bIsFolderPicker
;
78 QWidget
* m_pParentWidget
;
81 std::unique_ptr
<QFileDialog
> m_pFileDialog
; ///< the file picker dialog
82 QWidget
* m_pExtraControls
; ///< widget to contain extra custom controls
85 // use non-native file dialog by default; there's no easy way to add custom widgets
86 // in a generic way in the native one
87 explicit Qt5FilePicker(css::uno::Reference
<css::uno::XComponentContext
> const& context
,
88 QFileDialog::FileMode
, bool bUseNative
= false);
89 virtual ~Qt5FilePicker() override
;
91 // XFilePickerNotifier
92 virtual void SAL_CALL
addFilePickerListener(
93 const css::uno::Reference
<css::ui::dialogs::XFilePickerListener
>& xListener
) override
;
94 virtual void SAL_CALL
removeFilePickerListener(
95 const css::uno::Reference
<css::ui::dialogs::XFilePickerListener
>& xListener
) override
;
97 // XFilterManager functions
98 virtual void SAL_CALL
appendFilter(const OUString
& rTitle
, const OUString
& rFilter
) override
;
99 virtual void SAL_CALL
setCurrentFilter(const OUString
& rTitle
) override
;
100 virtual OUString SAL_CALL
getCurrentFilter() override
;
102 // XFilterGroupManager functions
103 virtual void SAL_CALL
104 appendFilterGroup(const OUString
& rGroupTitle
,
105 const css::uno::Sequence
<css::beans::StringPair
>& rFilters
) override
;
108 virtual void SAL_CALL
cancel() override
;
110 // XExecutableDialog functions
111 virtual void SAL_CALL
setTitle(const OUString
& rTitle
) override
;
112 virtual sal_Int16 SAL_CALL
execute() override
;
114 // XFilePicker functions
115 virtual void SAL_CALL
setMultiSelectionMode(sal_Bool bMode
) override
;
116 virtual void SAL_CALL
setDefaultName(const OUString
& rName
) override
;
117 virtual void SAL_CALL
setDisplayDirectory(const OUString
& rDirectory
) override
;
118 virtual OUString SAL_CALL
getDisplayDirectory() override
;
119 virtual css::uno::Sequence
<OUString
> SAL_CALL
getFiles() override
;
121 // XFilePickerControlAccess functions
122 virtual void SAL_CALL
setValue(sal_Int16 nControlId
, sal_Int16 nControlAction
,
123 const css::uno::Any
& rValue
) override
;
124 virtual css::uno::Any SAL_CALL
getValue(sal_Int16 nControlId
,
125 sal_Int16 nControlAction
) override
;
126 virtual void SAL_CALL
enableControl(sal_Int16 nControlId
, sal_Bool bEnable
) override
;
127 virtual void SAL_CALL
setLabel(sal_Int16 nControlId
, const OUString
& rLabel
) override
;
128 virtual OUString SAL_CALL
getLabel(sal_Int16 nControlId
) override
;
130 // XFilePicker2 functions
131 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSelectedFiles() override
;
134 virtual void SAL_CALL
initialize(const css::uno::Sequence
<css::uno::Any
>& rArguments
) override
;
137 void SAL_CALL
disposing(const css::lang::EventObject
& rEvent
) override
;
138 using cppu::WeakComponentImplHelperBase::disposing
;
141 virtual OUString SAL_CALL
getImplementationName() override
;
142 virtual sal_Bool SAL_CALL
supportsService(const OUString
& rServiceName
) override
;
143 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
145 // XFolderPicker functions
146 virtual OUString SAL_CALL
getDirectory() override
;
147 virtual void SAL_CALL
setDescription(const OUString
& rDescription
) override
;
149 // XTerminateListener
150 void SAL_CALL
queryTermination(const css::lang::EventObject
& aEvent
) override
;
151 void SAL_CALL
notifyTermination(const css::lang::EventObject
& aEvent
) override
;
154 virtual void addCustomControl(sal_Int16 controlId
);
155 void setCustomControlWidgetLayout(QGridLayout
* pLayout
) { m_pLayout
= pLayout
; }
158 Qt5FilePicker(const Qt5FilePicker
&) = delete;
159 Qt5FilePicker
& operator=(const Qt5FilePicker
&) = delete;
161 static QString
getResString(const char* pRedId
);
162 static css::uno::Any
handleGetListValue(const QComboBox
* pWidget
, sal_Int16 nControlAction
);
163 static void handleSetListValue(QComboBox
* pQComboBox
, sal_Int16 nAction
,
164 const css::uno::Any
& rValue
);
167 // emit XFilePickerListener controlStateChanged event
168 void filterSelected(const QString
&);
169 // emit XFilePickerListener fileSelectionChanged event
170 void currentChanged(const QString
&);
171 // (un)set automatic file extension
172 virtual void updateAutomaticFileExtension();
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */