Kaydet (Commit) 6196b729 authored tarafından Katarina Behrens's avatar Katarina Behrens

Copy filepicker classes from gtk3_kde5, don't build yet

Change-Id: Ic18add9e1e0a6a7e4480df17885670a0796f074a
üst ea1e0581
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "kde5_filepicker.hxx"
#include <KWindowSystem>
#include <KFileWidget>
#include <QtCore/QDebug>
#include <QtCore/QUrl>
#include <QtGui/QClipboard>
#include <QtGui/QWindow>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QWidget>
#include <QtWidgets/QApplication>
// KDE5FilePicker
KDE5FilePicker::KDE5FilePicker(QObject* parent)
: QObject(parent)
, _dialog(new QFileDialog(nullptr, {}, QDir::homePath()))
, _extraControls(new QWidget)
, _layout(new QGridLayout(_extraControls))
, _winId(0)
, allowRemoteUrls(false)
{
_dialog->setSupportedSchemes({
QStringLiteral("file"),
QStringLiteral("ftp"),
QStringLiteral("http"),
QStringLiteral("https"),
QStringLiteral("webdav"),
QStringLiteral("webdavs"),
QStringLiteral("smb"),
});
setMultiSelectionMode(false);
connect(_dialog, &QFileDialog::filterSelected, this, &KDE5FilePicker::filterChanged);
connect(_dialog, &QFileDialog::fileSelected, this, &KDE5FilePicker::selectionChanged);
qApp->installEventFilter(this);
}
void KDE5FilePicker::enableFolderMode()
{
_dialog->setOption(QFileDialog::ShowDirsOnly, true);
_dialog->setFileMode(QFileDialog::Directory);
}
KDE5FilePicker::~KDE5FilePicker()
{
delete _extraControls;
delete _dialog;
}
void KDE5FilePicker::setTitle(const QString& title) { _dialog->setWindowTitle(title); }
bool KDE5FilePicker::execute()
{
if (!_filters.isEmpty())
_dialog->setNameFilters(_filters);
if (!_currentFilter.isEmpty())
_dialog->selectNameFilter(_currentFilter);
_dialog->show();
//block and wait for user input
return _dialog->exec() == QFileDialog::Accepted;
}
void KDE5FilePicker::setMultiSelectionMode(bool multiSelect)
{
_dialog->setFileMode(multiSelect ? QFileDialog::ExistingFiles : QFileDialog::ExistingFile);
}
void KDE5FilePicker::setDefaultName(const QString& name) { _dialog->selectUrl(QUrl(name)); }
void KDE5FilePicker::setDisplayDirectory(const QString& dir) { _dialog->selectUrl(QUrl(dir)); }
QString KDE5FilePicker::getDisplayDirectory() const { return _dialog->directoryUrl().url(); }
QList<QUrl> KDE5FilePicker::getSelectedFiles() const { return _dialog->selectedUrls(); }
void KDE5FilePicker::appendFilter(const QString& title, const QString& filter)
{
QString t = title;
QString f = filter;
// '/' need to be escaped else they are assumed to be mime types by kfiledialog
//see the docs
t.replace("/", "\\/");
// openoffice gives us filters separated by ';' qt dialogs just want space separated
f.replace(";", " ");
// make sure "*.*" is not used as "all files"
f.replace("*.*", "*");
_filters << QStringLiteral("%1 (%2)").arg(t, f);
_titleToFilters[t] = _filters.constLast();
}
void KDE5FilePicker::setCurrentFilter(const QString& title)
{
_currentFilter = _titleToFilters.value(title);
}
QString KDE5FilePicker::getCurrentFilter() const
{
QString filter = _titleToFilters.key(_dialog->selectedNameFilter());
//default if not found
if (filter.isEmpty())
filter = "ODF Text Document (.odt)";
return filter;
}
void KDE5FilePicker::setValue(sal_Int16 controlId, sal_Int16 /*nControlAction*/, bool value)
{
if (_customWidgets.contains(controlId))
{
QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
if (cb)
cb->setChecked(value);
}
else
qWarning() << "set value on unknown control" << controlId;
}
bool KDE5FilePicker::getValue(sal_Int16 controlId, sal_Int16 /*nControlAction*/) const
{
bool ret = false;
if (_customWidgets.contains(controlId))
{
QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
if (cb)
ret = cb->isChecked();
}
else
qWarning() << "get value on unknown control" << controlId;
return ret;
}
void KDE5FilePicker::enableControl(sal_Int16 controlId, bool enable)
{
if (_customWidgets.contains(controlId))
_customWidgets.value(controlId)->setEnabled(enable);
else
qWarning() << "enable on unknown control" << controlId;
}
void KDE5FilePicker::setLabel(sal_Int16 controlId, const QString& label)
{
if (_customWidgets.contains(controlId))
{
QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
if (cb)
cb->setText(label);
}
else
qWarning() << "set label on unknown control" << controlId;
}
QString KDE5FilePicker::getLabel(sal_Int16 controlId) const
{
QString label;
if (_customWidgets.contains(controlId))
{
QCheckBox* cb = dynamic_cast<QCheckBox*>(_customWidgets.value(controlId));
if (cb)
label = cb->text();
}
else
qWarning() << "get label on unknown control" << controlId;
return label;
}
void KDE5FilePicker::addCheckBox(sal_Int16 controlId, const QString& label, bool hidden)
{
auto resString = label;
resString.replace('~', '&');
auto widget = new QCheckBox(resString, _extraControls);
widget->setHidden(hidden);
if (!hidden)
{
_layout->addWidget(widget);
}
_customWidgets.insert(controlId, widget);
}
void KDE5FilePicker::initialize(bool saveDialog)
{
//default is opening
QFileDialog::AcceptMode operationMode
= saveDialog ? QFileDialog::AcceptSave : QFileDialog::AcceptOpen;
_dialog->setAcceptMode(operationMode);
if (saveDialog)
{
_dialog->setConfirmOverwrite(true);
_dialog->setFileMode(QFileDialog::AnyFile);
}
}
void KDE5FilePicker::setWinId(sal_uIntPtr winId) { _winId = winId; }
bool KDE5FilePicker::eventFilter(QObject* o, QEvent* e)
{
if (e->type() == QEvent::Show && o->isWidgetType())
{
auto* w = static_cast<QWidget*>(o);
if (!w->parentWidget() && w->isModal())
{
KWindowSystem::setMainWindow(w, _winId);
if (auto* fileWidget = w->findChild<KFileWidget*>({}, Qt::FindDirectChildrenOnly))
fileWidget->setCustomWidget(_extraControls);
}
}
return QObject::eventFilter(o, e);
}
#include <kde5_filepicker.moc>
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QHash>
#include <sal/types.h>
class QFileDialog;
class QWidget;
class QGridLayout;
class KDE5FilePicker : public QObject
{
Q_OBJECT
protected:
//the dialog to display
QFileDialog* _dialog;
//running filter string to add to dialog
QStringList _filters;
// map of filter titles to full filter for selection
QHash<QString, QString> _titleToFilters;
// string to set the current filter
QString _currentFilter;
//mapping of SAL control ID's to created custom controls
QHash<sal_Int16, QWidget*> _customWidgets;
//widget to contain extra custom controls
QWidget* _extraControls;
//layout for extra custom controls
QGridLayout* _layout;
sal_uIntPtr _winId;
bool allowRemoteUrls;
public:
explicit KDE5FilePicker(QObject* parent = nullptr);
~KDE5FilePicker() override;
void enableFolderMode();
// XExecutableDialog functions
void setTitle(const QString& rTitle);
bool execute();
// XFilePicker functions
void setMultiSelectionMode(bool bMode);
void setDefaultName(const QString& rName);
void setDisplayDirectory(const QString& rDirectory);
QString getDisplayDirectory() const;
// XFilterManager functions
void appendFilter(const QString& rTitle, const QString& rFilter);
void setCurrentFilter(const QString& rTitle);
QString getCurrentFilter() const;
// XFilePickerControlAccess functions
void setValue(sal_Int16 nControlId, sal_Int16 nControlAction, bool rValue);
bool getValue(sal_Int16 nControlId, sal_Int16 nControlAction) const;
void enableControl(sal_Int16 nControlId, bool bEnable);
void setLabel(sal_Int16 nControlId, const QString& rLabel);
QString getLabel(sal_Int16 nControlId) const;
// XFilePicker2 functions
QList<QUrl> getSelectedFiles() const;
// XInitialization
void initialize(bool saveDialog);
//add a custom control widget to the file dialog
void addCheckBox(sal_Int16 nControlId, const QString& label, bool hidden);
void setWinId(sal_uIntPtr winId);
private:
Q_DISABLE_COPY(KDE5FilePicker)
protected:
bool eventFilter(QObject* watched, QEvent* event) override;
Q_SIGNALS:
void filterChanged();
void selectionChanged();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "gtk3_kde5_filepicker.hxx"
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
#include <cppuhelper/interfacecontainer.h>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/ControlActions.hpp>
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <osl/mutex.hxx>
#include <fpicker/strings.hrc>
#include "FPServiceInfo.hxx"
#undef Region
#include <unx/geninst.h>
#include <strings.hrc>
using namespace ::com::sun::star;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
// helper functions
namespace
{
uno::Sequence<OUString> FilePicker_getSupportedServiceNames()
{
uno::Sequence<OUString> aRet(3);
aRet[0] = "com.sun.star.ui.dialogs.FilePicker";
aRet[1] = "com.sun.star.ui.dialogs.SystemFilePicker";
aRet[2] = "com.sun.star.ui.dialogs.KDE5FilePicker2";
return aRet;
}
}
// KDE5FilePicker2
KDE5FilePicker2::KDE5FilePicker2(const uno::Reference<uno::XComponentContext>&)
: KDE5FilePicker2_Base(_helperMutex)
{
setMultiSelectionMode(false);
}
KDE5FilePicker2::~KDE5FilePicker2() = default;
void SAL_CALL
KDE5FilePicker2::addFilePickerListener(const uno::Reference<XFilePickerListener>& xListener)
{
SolarMutexGuard aGuard;
m_xListener = xListener;
}
void SAL_CALL KDE5FilePicker2::removeFilePickerListener(const uno::Reference<XFilePickerListener>&)
{
SolarMutexGuard aGuard;
m_xListener.clear();
}
void SAL_CALL KDE5FilePicker2::setTitle(const OUString& title)
{
m_ipc.sendCommand(Commands::SetTitle, title);
}
sal_Int16 SAL_CALL KDE5FilePicker2::execute() { return m_ipc.execute(); }
void SAL_CALL KDE5FilePicker2::setMultiSelectionMode(sal_Bool multiSelect)
{
m_ipc.sendCommand(Commands::SetMultiSelectionMode, bool(multiSelect));
}
void SAL_CALL KDE5FilePicker2::setDefaultName(const OUString& name)
{
m_ipc.sendCommand(Commands::SetDefaultName, name);
}
void SAL_CALL KDE5FilePicker2::setDisplayDirectory(const OUString& dir)
{
m_ipc.sendCommand(Commands::SetDisplayDirectory, dir);
}
OUString SAL_CALL KDE5FilePicker2::getDisplayDirectory()
{
auto id = m_ipc.sendCommand(Commands::GetDisplayDirectory);
OUString dir;
m_ipc.readResponse(id, dir);
return dir;
}
uno::Sequence<OUString> SAL_CALL KDE5FilePicker2::getFiles()
{
uno::Sequence<OUString> seq = getSelectedFiles();
if (seq.getLength() > 1)
seq.realloc(1);
return seq;
}
uno::Sequence<OUString> SAL_CALL KDE5FilePicker2::getSelectedFiles()
{
auto id = m_ipc.sendCommand(Commands::GetSelectedFiles);
uno::Sequence<OUString> seq;
m_ipc.readResponse(id, seq);
return seq;
}
void SAL_CALL KDE5FilePicker2::appendFilter(const OUString& title, const OUString& filter)
{
m_ipc.sendCommand(Commands::AppendFilter, title, filter);
}
void SAL_CALL KDE5FilePicker2::setCurrentFilter(const OUString& title)
{
m_ipc.sendCommand(Commands::SetCurrentFilter, title);
}
OUString SAL_CALL KDE5FilePicker2::getCurrentFilter()
{
auto id = m_ipc.sendCommand(Commands::GetCurrentFilter);
OUString filter;
m_ipc.readResponse(id, filter);
return filter;
}
void SAL_CALL KDE5FilePicker2::appendFilterGroup(const OUString& /*rGroupTitle*/,
const uno::Sequence<beans::StringPair>& filters)
{
const sal_uInt16 length = filters.getLength();
for (sal_uInt16 i = 0; i < length; ++i)
{
beans::StringPair aPair = filters[i];
appendFilter(aPair.First, aPair.Second);
}
}
void SAL_CALL KDE5FilePicker2::setValue(sal_Int16 controlId, sal_Int16 nControlAction,
const uno::Any& value)
{
if (value.has<bool>())
{
m_ipc.sendCommand(Commands::SetValue, controlId, nControlAction, value.get<bool>());
}
else
{
OSL_TRACE("set value of unhandled type %d", controlId);
}
}
uno::Any SAL_CALL KDE5FilePicker2::getValue(sal_Int16 controlId, sal_Int16 nControlAction)
{
if (CHECKBOX_AUTOEXTENSION == controlId)
// We ignore this one and rely on QFileDialog to provide the function.
// Always return false, to pretend we do not support this, otherwise
// LO core would try to be smart and cut the extension in some places,
// interfering with QFileDialog's handling of it. QFileDialog also
// saves the value of the setting, so LO core is not needed for that either.
return uno::Any(false);
auto id = m_ipc.sendCommand(Commands::GetValue, controlId, nControlAction);
bool value = false;
m_ipc.readResponse(id, value);
return uno::Any(value);
}
void SAL_CALL KDE5FilePicker2::enableControl(sal_Int16 controlId, sal_Bool enable)
{
m_ipc.sendCommand(Commands::EnableControl, controlId, bool(enable));
}
void SAL_CALL KDE5FilePicker2::setLabel(sal_Int16 controlId, const OUString& label)
{
m_ipc.sendCommand(Commands::SetLabel, controlId, label);
}
OUString SAL_CALL KDE5FilePicker2::getLabel(sal_Int16 controlId)
{
auto id = m_ipc.sendCommand(Commands::GetLabel, controlId);
OUString label;
m_ipc.readResponse(id, label);
return label;
}
void KDE5FilePicker2::addCustomControl(sal_Int16 controlId)
{
const char* resId = nullptr;
switch (controlId)
{
case CHECKBOX_AUTOEXTENSION:
resId = STR_FPICKER_AUTO_EXTENSION;
break;
case CHECKBOX_PASSWORD:
resId = STR_FPICKER_PASSWORD;
break;
case CHECKBOX_FILTEROPTIONS:
resId = STR_FPICKER_FILTER_OPTIONS;
break;
case CHECKBOX_READONLY:
resId = STR_FPICKER_READONLY;
break;
case CHECKBOX_LINK:
resId = STR_FPICKER_INSERT_AS_LINK;
break;
case CHECKBOX_PREVIEW:
resId = STR_FPICKER_SHOW_PREVIEW;
break;
case CHECKBOX_SELECTION:
resId = STR_FPICKER_SELECTION;
break;
case CHECKBOX_GPGENCRYPTION:
resId = STR_FPICKER_GPGENCRYPT;
break;
case PUSHBUTTON_PLAY:
resId = STR_FPICKER_PLAY;
break;
case LISTBOX_VERSION:
resId = STR_FPICKER_VERSION;
break;
case LISTBOX_TEMPLATE:
resId = STR_FPICKER_TEMPLATES;
break;
case LISTBOX_IMAGE_TEMPLATE:
resId = STR_FPICKER_IMAGE_TEMPLATE;
break;
case LISTBOX_IMAGE_ANCHOR:
resId = STR_FPICKER_IMAGE_ANCHOR;
break;
case LISTBOX_VERSION_LABEL:
case LISTBOX_TEMPLATE_LABEL:
case LISTBOX_IMAGE_TEMPLATE_LABEL:
case LISTBOX_IMAGE_ANCHOR_LABEL:
case LISTBOX_FILTER_SELECTOR:
break;
}
switch (controlId)
{
case CHECKBOX_AUTOEXTENSION:
case CHECKBOX_PASSWORD:
case CHECKBOX_FILTEROPTIONS:
case CHECKBOX_READONLY:
case CHECKBOX_LINK:
case CHECKBOX_PREVIEW:
case CHECKBOX_SELECTION:
case CHECKBOX_GPGENCRYPTION:
{
// the checkbox is created even for CHECKBOX_AUTOEXTENSION to simplify
// code, but the checkbox is hidden and ignored
bool hidden = controlId == CHECKBOX_AUTOEXTENSION;
m_ipc.sendCommand(Commands::AddCheckBox, controlId, hidden, getResString(resId));
break;
}
case PUSHBUTTON_PLAY:
case LISTBOX_VERSION:
case LISTBOX_TEMPLATE:
case LISTBOX_IMAGE_TEMPLATE:
case LISTBOX_IMAGE_ANCHOR:
case LISTBOX_VERSION_LABEL:
case LISTBOX_TEMPLATE_LABEL:
case LISTBOX_IMAGE_TEMPLATE_LABEL:
case LISTBOX_IMAGE_ANCHOR_LABEL:
case LISTBOX_FILTER_SELECTOR:
break;
}
}
void SAL_CALL KDE5FilePicker2::initialize(const uno::Sequence<uno::Any>& args)
{
// parameter checking
uno::Any arg;
if (args.getLength() == 0)
{
throw lang::IllegalArgumentException("no arguments", static_cast<XFilePicker2*>(this), 1);
}
arg = args[0];
if ((arg.getValueType() != cppu::UnoType<sal_Int16>::get())
&& (arg.getValueType() != cppu::UnoType<sal_Int8>::get()))
{
throw lang::IllegalArgumentException("invalid argument type",
static_cast<XFilePicker2*>(this), 1);
}
sal_Int16 templateId = -1;
arg >>= templateId;
bool saveDialog = false;
switch (templateId)
{
case FILEOPEN_SIMPLE:
break;
case FILESAVE_SIMPLE:
saveDialog = true;
break;
case FILESAVE_AUTOEXTENSION:
saveDialog = true;
addCustomControl(CHECKBOX_AUTOEXTENSION);
break;
case FILESAVE_AUTOEXTENSION_PASSWORD:
{
saveDialog = true;
addCustomControl(CHECKBOX_PASSWORD);
addCustomControl(CHECKBOX_GPGENCRYPTION);
break;
}
case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
{
saveDialog = true;
addCustomControl(CHECKBOX_AUTOEXTENSION);
addCustomControl(CHECKBOX_PASSWORD);
addCustomControl(CHECKBOX_GPGENCRYPTION);
addCustomControl(CHECKBOX_FILTEROPTIONS);
break;
}
case FILESAVE_AUTOEXTENSION_SELECTION:
saveDialog = true;
addCustomControl(CHECKBOX_AUTOEXTENSION);
addCustomControl(CHECKBOX_SELECTION);
break;
case FILESAVE_AUTOEXTENSION_TEMPLATE:
saveDialog = true;
addCustomControl(CHECKBOX_AUTOEXTENSION);
addCustomControl(LISTBOX_TEMPLATE);
break;
case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
addCustomControl(CHECKBOX_LINK);
addCustomControl(CHECKBOX_PREVIEW);
addCustomControl(LISTBOX_IMAGE_TEMPLATE);
break;
case FILEOPEN_LINK_PREVIEW_IMAGE_ANCHOR:
addCustomControl(CHECKBOX_LINK);
addCustomControl(CHECKBOX_PREVIEW);
addCustomControl(LISTBOX_IMAGE_ANCHOR);
break;
case FILEOPEN_PLAY:
addCustomControl(PUSHBUTTON_PLAY);
break;
case FILEOPEN_LINK_PLAY:
addCustomControl(CHECKBOX_LINK);
addCustomControl(PUSHBUTTON_PLAY);
break;
case FILEOPEN_READONLY_VERSION:
addCustomControl(CHECKBOX_READONLY);
addCustomControl(LISTBOX_VERSION);
break;
case FILEOPEN_LINK_PREVIEW:
addCustomControl(CHECKBOX_LINK);
addCustomControl(CHECKBOX_PREVIEW);
break;
case FILEOPEN_PREVIEW:
addCustomControl(CHECKBOX_PREVIEW);
break;
default:
OSL_TRACE("Unknown templates %d", templateId);
return;
}
setTitle(getResString(saveDialog ? STR_FPICKER_SAVE : STR_FPICKER_OPEN));
m_ipc.sendCommand(Commands::Initialize, saveDialog);
}
void SAL_CALL KDE5FilePicker2::cancel()
{
// TODO
}
void KDE5FilePicker2::disposing(const lang::EventObject& rEvent)
{
uno::Reference<XFilePickerListener> xFilePickerListener(rEvent.Source, uno::UNO_QUERY);
if (xFilePickerListener.is())
{
removeFilePickerListener(xFilePickerListener);
}
}
OUString SAL_CALL KDE5FilePicker2::getImplementationName()
{
return OUString(FILE_PICKER_IMPL_NAME);
}
sal_Bool SAL_CALL KDE5FilePicker2::supportsService(const OUString& ServiceName)
{
return cppu::supportsService(this, ServiceName);
}
uno::Sequence<OUString> SAL_CALL KDE5FilePicker2::getSupportedServiceNames()
{
return FilePicker_getSupportedServiceNames();
}
void KDE5FilePicker2::filterChanged()
{
FilePickerEvent aEvent;
aEvent.ElementId = LISTBOX_FILTER;
OSL_TRACE("filter changed");
if (m_xListener.is())
m_xListener->controlStateChanged(aEvent);
}
void KDE5FilePicker2::selectionChanged()
{
FilePickerEvent aEvent;
OSL_TRACE("file selection changed");
if (m_xListener.is())
m_xListener->fileSelectionChanged(aEvent);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#pragma once
#include <cppuhelper/compbase.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <rtl/ustrbuf.hxx>
#include "gtk3_kde5_filepicker_ipc.hxx"
#include <functional>
typedef ::cppu::WeakComponentImplHelper<css::ui::dialogs::XFilePicker3,
css::ui::dialogs::XFilePickerControlAccess
// TODO css::ui::dialogs::XFilePreview
,
css::lang::XInitialization, css::lang::XServiceInfo>
KDE5FilePicker2_Base;
class KDE5FilePicker2 : public KDE5FilePicker2_Base
{
protected:
css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener;
osl::Mutex _helperMutex;
KDE5FilePicker2Ipc m_ipc;
public:
explicit KDE5FilePicker2(const css::uno::Reference<css::uno::XComponentContext>&);
virtual ~KDE5FilePicker2() override;
// XFilePickerNotifier
virtual void SAL_CALL addFilePickerListener(
const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;
virtual void SAL_CALL removeFilePickerListener(
const css::uno::Reference<css::ui::dialogs::XFilePickerListener>& xListener) override;
// XExecutableDialog functions
virtual void SAL_CALL setTitle(const OUString& rTitle) override;
virtual sal_Int16 SAL_CALL execute() override;
// XFilePicker functions
virtual void SAL_CALL setMultiSelectionMode(sal_Bool bMode) override;
virtual void SAL_CALL setDefaultName(const OUString& rName) override;
virtual void SAL_CALL setDisplayDirectory(const OUString& rDirectory) override;
virtual OUString SAL_CALL getDisplayDirectory() override;
virtual css::uno::Sequence<OUString> SAL_CALL getFiles() override;
// XFilterManager functions
virtual void SAL_CALL appendFilter(const OUString& rTitle, const OUString& rFilter) override;
virtual void SAL_CALL setCurrentFilter(const OUString& rTitle) override;
virtual OUString SAL_CALL getCurrentFilter() override;
// XFilterGroupManager functions
virtual void SAL_CALL
appendFilterGroup(const OUString& rGroupTitle,
const css::uno::Sequence<css::beans::StringPair>& rFilters) override;
// XFilePickerControlAccess functions
virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction,
const css::uno::Any& rValue) override;
virtual css::uno::Any SAL_CALL getValue(sal_Int16 nControlId,
sal_Int16 nControlAction) override;
virtual void SAL_CALL enableControl(sal_Int16 nControlId, sal_Bool bEnable) override;
virtual void SAL_CALL setLabel(sal_Int16 nControlId, const OUString& rLabel) override;
virtual OUString SAL_CALL getLabel(sal_Int16 nControlId) override;
/* TODO XFilePreview
virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats( );
virtual sal_Int32 SAL_CALL getTargetColorDepth( );
virtual sal_Int32 SAL_CALL getAvailableWidth( );
virtual sal_Int32 SAL_CALL getAvailableHeight( );
virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const css::uno::Any &rImage );
virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState );
virtual sal_Bool SAL_CALL getShowState( );
*/
// XFilePicker2 functions
virtual css::uno::Sequence<OUString> SAL_CALL getSelectedFiles() override;
// XInitialization
virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override;
// XCancellable
virtual void SAL_CALL cancel() override;
// XEventListener
virtual void disposing(const css::lang::EventObject& rEvent);
using cppu::WeakComponentImplHelperBase::disposing;
// XServiceInfo
virtual OUString SAL_CALL getImplementationName() override;
virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
private:
KDE5FilePicker2(const KDE5FilePicker2&) = delete;
KDE5FilePicker2& operator=(const KDE5FilePicker2&) = delete;
//add a custom control widget to the file dialog
void addCustomControl(sal_Int16 controlId);
// emit XFilePickerListener controlStateChanged event
void filterChanged();
// emit XFilePickerListener fileSelectionChanged event
void selectionChanged();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment