nss: upgrade to release 3.73
[LibreOffice.git] / vcl / unx / kf5 / KF5FilePicker.cxx
blob20e64007bd96a672bb80e8e4a8c7c1e4da1a6529
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 #include "KF5FilePicker.hxx"
21 #include <KF5FilePicker.moc>
23 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <osl/mutex.hxx>
27 #include <qt5/Qt5Instance.hxx>
29 #include <QtWidgets/QApplication>
30 #include <QtWidgets/QGridLayout>
31 #include <QtWidgets/QWidget>
32 #include <KFileWidget>
34 using namespace ::com::sun::star;
35 using ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION;
37 namespace
39 uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
41 return { "com.sun.star.ui.dialogs.FilePicker", "com.sun.star.ui.dialogs.SystemFilePicker",
42 "com.sun.star.ui.dialogs.KF5FilePicker", "com.sun.star.ui.dialogs.KF5FolderPicker" };
46 // KF5FilePicker
48 KF5FilePicker::KF5FilePicker(css::uno::Reference<css::uno::XComponentContext> const& context,
49 QFileDialog::FileMode eMode)
50 // Native kf5 filepicker does not add file extension automatically
51 : Qt5FilePicker(context, eMode, true)
52 , _layout(new QGridLayout(m_pExtraControls))
54 // only columns 0 and 1 are used by controls (s. Qt5FilePicker::addCustomControl);
55 // set stretch for (unused) column 2 in order for the controls to only take the space
56 // they actually need and avoid empty space in between
57 _layout->setColumnStretch(2, 1);
59 // set layout so custom widgets show up in our native file dialog
60 setCustomControlWidgetLayout(_layout.get());
62 m_pFileDialog->setSupportedSchemes({
63 QStringLiteral("file"), QStringLiteral("ftp"), QStringLiteral("http"),
64 QStringLiteral("https"), QStringLiteral("webdav"), QStringLiteral("webdavs"),
65 QStringLiteral("smb"),
66 QStringLiteral(""), // this makes removable devices shown
67 });
69 // used to set the custom controls
70 qApp->installEventFilter(this);
73 // XFilePickerControlAccess
74 void SAL_CALL KF5FilePicker::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
75 const uno::Any& value)
77 if (CHECKBOX_AUTOEXTENSION == controlId)
78 // We ignore this one and rely on QFileDialog to provide the functionality
79 return;
81 Qt5FilePicker::setValue(controlId, nControlAction, value);
84 uno::Any SAL_CALL KF5FilePicker::getValue(sal_Int16 controlId, sal_Int16 nControlAction)
86 SolarMutexGuard g;
87 auto* pSalInst(static_cast<Qt5Instance*>(GetSalData()->m_pInstance));
88 assert(pSalInst);
89 if (!pSalInst->IsMainThread())
91 uno::Any ret;
92 pSalInst->RunInMainThread([&ret, this, controlId, nControlAction]() {
93 ret = getValue(controlId, nControlAction);
94 });
95 return ret;
98 if (CHECKBOX_AUTOEXTENSION == controlId)
99 // We ignore this one and rely on QFileDialog to provide the function.
100 // Always return false, to pretend we do not support this, otherwise
101 // LO core would try to be smart and cut the extension in some places,
102 // interfering with QFileDialog's handling of it. QFileDialog also
103 // saves the value of the setting, so LO core is not needed for that either.
104 return uno::Any(false);
106 return Qt5FilePicker::getValue(controlId, nControlAction);
109 void SAL_CALL KF5FilePicker::enableControl(sal_Int16 controlId, sal_Bool enable)
111 if (CHECKBOX_AUTOEXTENSION == controlId)
112 // We ignore this one and rely on QFileDialog to provide the functionality
113 return;
115 Qt5FilePicker::enableControl(controlId, enable);
118 void SAL_CALL KF5FilePicker::setLabel(sal_Int16 controlId, const OUString& label)
120 if (CHECKBOX_AUTOEXTENSION == controlId)
121 // We ignore this one and rely on QFileDialog to provide the functionality
122 return;
124 Qt5FilePicker::setLabel(controlId, label);
127 OUString SAL_CALL KF5FilePicker::getLabel(sal_Int16 controlId)
129 // We ignore this one and rely on QFileDialog to provide the functionality
130 if (CHECKBOX_AUTOEXTENSION == controlId)
131 return "";
133 return Qt5FilePicker::getLabel(controlId);
136 void KF5FilePicker::addCustomControl(sal_Int16 controlId)
138 // native kf5 filepicker has its own autoextension checkbox,
139 // therefore avoid adding yet another one
140 if (controlId == CHECKBOX_AUTOEXTENSION)
141 return;
143 Qt5FilePicker::addCustomControl(controlId);
146 // XServiceInfo
147 OUString SAL_CALL KF5FilePicker::getImplementationName()
149 return "com.sun.star.ui.dialogs.KF5FilePicker";
152 sal_Bool SAL_CALL KF5FilePicker::supportsService(const OUString& ServiceName)
154 return cppu::supportsService(this, ServiceName);
157 uno::Sequence<OUString> SAL_CALL KF5FilePicker::getSupportedServiceNames()
159 return FilePicker_getSupportedServiceNames();
162 bool KF5FilePicker::eventFilter(QObject* o, QEvent* e)
164 if (e->type() == QEvent::Show && o->isWidgetType())
166 auto* w = static_cast<QWidget*>(o);
167 if (!w->parentWidget() && w->isModal())
169 if (auto* fileWidget = w->findChild<KFileWidget*>({}, Qt::FindDirectChildrenOnly))
171 fileWidget->setCustomWidget(m_pExtraControls);
172 // remove event filter again; the only purpose was to set the custom widget here
173 qApp->removeEventFilter(this);
177 return QObject::eventFilter(o, e);
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */