LibreOffice Module vcl (master) 1
qt5/QtFilePicker.hxx
Go to the documentation of this file.
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
20#pragma once
21
22#include <vclpluginapi.h>
23
25
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/XAsynchronousExecutableDialog.hpp>
30#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
31#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
32#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
33#include <com/sun/star/uno/XComponentContext.hpp>
34
35#include <osl/conditn.hxx>
36#include <osl/mutex.hxx>
37#include <unotools/resmgr.hxx>
38
39#include <QtCore/QObject>
40#include <QtCore/QString>
41#include <QtCore/QStringList>
42#include <QtCore/QHash>
43#include <QtWidgets/QFileDialog>
44
45#include <memory>
46
47class QComboBox;
48class QGridLayout;
49class QLabel;
50class QWidget;
51
52typedef ::cppu::WeakComponentImplHelper<
53 css::frame::XTerminateListener, css::lang::XInitialization, css::lang::XServiceInfo,
54 css::ui::dialogs::XFilePicker3, css::ui::dialogs::XFilePickerControlAccess,
55 css::ui::dialogs::XAsynchronousExecutableDialog, css::ui::dialogs::XFolderPicker2>
57
58class VCLPLUG_QT_PUBLIC QtFilePicker : public QObject, public QtFilePicker_Base
59{
60 Q_OBJECT
61
62private:
63 css::uno::Reference<css::uno::XComponentContext> m_context;
64
65 css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener;
66 css::uno::Reference<css::ui::dialogs::XDialogClosedListener> m_xClosedListener;
67
68 osl::Mutex m_aHelperMutex;
69
70 QStringList m_aNamedFilterList;
71 QHash<QString, QString> m_aTitleToFilterMap;
72 // to retrieve the filename extension for a given filter
73 QHash<QString, QString> m_aNamedFilterToExtensionMap;
75
76 QGridLayout* m_pLayout;
77 QHash<sal_Int16, QWidget*> m_aCustomWidgetsMap;
78
80
82
83protected:
84 std::unique_ptr<QFileDialog> m_pFileDialog;
86
87public:
88 // use non-native file dialog by default; there's no easy way to add custom widgets
89 // in a generic way in the native one
90 explicit QtFilePicker(css::uno::Reference<css::uno::XComponentContext> context,
91 QFileDialog::FileMode, bool bUseNative = false);
92 virtual ~QtFilePicker() override;
93
94 // XFilePickerNotifier
95 virtual void SAL_CALL addFilePickerListener(
96 const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;
97 virtual void SAL_CALL removeFilePickerListener(
98 const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;
99
100 // XFilterManager functions
101 virtual void SAL_CALL appendFilter(const OUString& rTitle, const OUString& rFilter) override;
102 virtual void SAL_CALL setCurrentFilter(const OUString& rTitle) override;
103 virtual OUString SAL_CALL getCurrentFilter() override;
104
105 // XFilterGroupManager functions
106 virtual void SAL_CALL
107 appendFilterGroup(const OUString& rGroupTitle,
108 const css::uno::Sequence<css::beans::StringPair>& rFilters) override;
109
110 // XCancellable
111 virtual void SAL_CALL cancel() override;
112
113 // XExecutableDialog functions
114 virtual void SAL_CALL setTitle(const OUString& rTitle) override;
115 virtual sal_Int16 SAL_CALL execute() override;
116
117 // XAsynchronousExecutableDialog functions
118 virtual void SAL_CALL setDialogTitle(const OUString&) override;
119 virtual void SAL_CALL
120 startExecuteModal(const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>&) override;
121
122 // XFilePicker functions
123 virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override;
124 virtual void SAL_CALL setDefaultName(const OUString& rName) override;
125 virtual void SAL_CALL setDisplayDirectory(const OUString& rDirectory) override;
126 virtual OUString SAL_CALL getDisplayDirectory() override;
127 virtual css::uno::Sequence<OUString> SAL_CALL getFiles() override;
128
129 // XFilePickerControlAccess functions
130 virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction,
131 const css::uno::Any& rValue) override;
132 virtual css::uno::Any SAL_CALL getValue(sal_Int16 nControlId,
133 sal_Int16 nControlAction) override;
134 virtual void SAL_CALL enableControl(sal_Int16 nControlId, sal_Bool bEnable) override;
135 virtual void SAL_CALL setLabel(sal_Int16 nControlId, const OUString& rLabel) override;
136 virtual OUString SAL_CALL getLabel(sal_Int16 nControlId) override;
137
138 // XFilePicker2 functions
139 virtual css::uno::Sequence<OUString> SAL_CALL getSelectedFiles() override;
140
141 // XInitialization
142 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
143
144 // XEventListener
145 void SAL_CALL disposing(const css::lang::EventObject& rEvent) override;
146 using cppu::WeakComponentImplHelperBase::disposing;
147
148 // XServiceInfo
149 virtual OUString SAL_CALL getImplementationName() override;
150 virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
151 virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
152
153 // XFolderPicker functions
154 virtual OUString SAL_CALL getDirectory() override;
155 virtual void SAL_CALL setDescription(const OUString& rDescription) override;
156
157 // XTerminateListener
158 void SAL_CALL queryTermination(const css::lang::EventObject& aEvent) override;
159 void SAL_CALL notifyTermination(const css::lang::EventObject& aEvent) override;
160
161protected:
162 virtual void addCustomControl(sal_Int16 controlId);
163 void setCustomControlWidgetLayout(QGridLayout* pLayout) { m_pLayout = pLayout; }
164
165private:
166 QtFilePicker(const QtFilePicker&) = delete;
168
169 static QString getResString(TranslateId pRedId);
170 static css::uno::Any handleGetListValue(const QComboBox* pWidget, sal_Int16 nControlAction);
171 static void handleSetListValue(QComboBox* pQComboBox, sal_Int16 nAction,
172 const css::uno::Any& rValue);
173
175
176private Q_SLOTS:
177 // emit XFilePickerListener controlStateChanged event
178 void filterSelected(const QString&);
179 // emit XFilePickerListener fileSelectionChanged event
180 void currentChanged(const QString&);
181 // (un)set automatic file extension
183 void finished(int);
184};
185
186/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Any handleGetListValue(const QComboBox *pWidget, sal_Int16 nControlAction)
void SAL_CALL disposing(const css::lang::EventObject &rEvent) override
void currentChanged(const QString &)
std::unique_ptr< QFileDialog > m_pFileDialog
the file picker dialog
virtual void addCustomControl(sal_Int16 controlId)
QStringList m_aNamedFilterList
to keep the original sequence
QHash< QString, QString > m_aTitleToFilterMap
virtual void SAL_CALL setDescription(const OUString &rDescription) override
osl::Mutex m_aHelperMutex
mutex used by the WeakComponentImplHelper
virtual void SAL_CALL appendFilter(const OUString &rTitle, const OUString &rFilter) override
virtual void SAL_CALL setLabel(sal_Int16 nControlId, const OUString &rLabel) override
css::uno::Reference< css::ui::dialogs::XDialogClosedListener > m_xClosedListener
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
void filterSelected(const QString &)
virtual OUString SAL_CALL getDisplayDirectory() override
virtual OUString SAL_CALL getCurrentFilter() override
void setCustomControlWidgetLayout(QGridLayout *pLayout)
virtual ~QtFilePicker() override
virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction, const css::uno::Any &rValue) override
QHash< QString, QString > m_aNamedFilterToExtensionMap
QtFilePicker(css::uno::Reference< css::uno::XComponentContext > context, QFileDialog::FileMode, bool bUseNative=false)
void finished(int)
virtual OUString SAL_CALL getImplementationName() override
static void handleSetListValue(QComboBox *pQComboBox, sal_Int16 nAction, const css::uno::Any &rValue)
QtFilePicker & operator=(const QtFilePicker &)=delete
QString m_aCurrentFilter
void SAL_CALL queryTermination(const css::lang::EventObject &aEvent) override
virtual void SAL_CALL setCurrentFilter(const OUString &rTitle) override
virtual sal_Int16 SAL_CALL execute() override
virtual void SAL_CALL appendFilterGroup(const OUString &rGroupTitle, const css::uno::Sequence< css::beans::StringPair > &rFilters) override
virtual void SAL_CALL setDialogTitle(const OUString &) override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &rArguments) override
QWidget * m_pExtraControls
widget to contain extra custom controls
virtual void updateAutomaticFileExtension()
static QString getResString(TranslateId pRedId)
void SAL_CALL notifyTermination(const css::lang::EventObject &aEvent) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override
virtual void SAL_CALL cancel() override
virtual void SAL_CALL setTitle(const OUString &rTitle) override
virtual OUString SAL_CALL getLabel(sal_Int16 nControlId) override
QHash< sal_Int16, QWidget * > m_aCustomWidgetsMap
map of SAL control ID's to widget
virtual css::uno::Sequence< OUString > SAL_CALL getSelectedFiles() override
virtual void SAL_CALL startExecuteModal(const css::uno::Reference< css::ui::dialogs::XDialogClosedListener > &) override
virtual void SAL_CALL setDisplayDirectory(const OUString &rDirectory) override
virtual void SAL_CALL addFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener) override
QtFilePicker(const QtFilePicker &)=delete
virtual css::uno::Any SAL_CALL getValue(sal_Int16 nControlId, sal_Int16 nControlAction) override
void prepareExecute()
const bool m_bIsFolderPicker
css::uno::Reference< css::ui::dialogs::XFilePickerListener > m_xListener
virtual void SAL_CALL removeFilePickerListener(const css::uno::Reference< css::ui::dialogs::XFilePickerListener > &xListener) override
virtual void SAL_CALL setDefaultName(const OUString &rName) override
virtual void SAL_CALL enableControl(sal_Int16 nControlId, sal_Bool bEnable) override
QGridLayout * m_pLayout
layout for extra custom controls
virtual OUString SAL_CALL getDirectory() override
virtual css::uno::Sequence< OUString > SAL_CALL getFiles() override
QWidget * m_pParentWidget
css::uno::Reference< css::uno::XComponentContext > m_context
::cppu::WeakComponentImplHelper< css::frame::XTerminateListener, css::lang::XInitialization, css::lang::XServiceInfo, css::ui::dialogs::XFilePicker3, css::ui::dialogs::XFilePickerControlAccess, css::ui::dialogs::XAsynchronousExecutableDialog, css::ui::dialogs::XFolderPicker2 > QtFilePicker_Base
unsigned char sal_Bool
#define VCLPLUG_QT_PUBLIC
Definition: vclpluginapi.h:53