bump product version to 7.2.5.1
[LibreOffice.git] / vcl / inc / qt5 / Qt5FilePicker.hxx
blob5fef2aaeae43d9fbfef368be400b80f231d4fd76
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 .
20 #pragma once
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>
43 #include <memory>
45 class QComboBox;
46 class QGridLayout;
47 class QLabel;
48 class QWidget;
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>
54 Qt5FilePicker_Base;
56 class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Base
58 Q_OBJECT
60 private:
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;
80 protected:
81 std::unique_ptr<QFileDialog> m_pFileDialog; ///< the file picker dialog
82 QWidget* m_pExtraControls; ///< widget to contain extra custom controls
84 public:
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;
107 // XCancellable
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;
133 // XInitialization
134 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
136 // XEventListener
137 void SAL_CALL disposing(const css::lang::EventObject& rEvent) override;
138 using cppu::WeakComponentImplHelperBase::disposing;
140 // XServiceInfo
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;
153 protected:
154 virtual void addCustomControl(sal_Int16 controlId);
155 void setCustomControlWidgetLayout(QGridLayout* pLayout) { m_pLayout = pLayout; }
157 private:
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);
166 private Q_SLOTS:
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: */