From 1f582e38dd8f2f9c556720e5d66d0d17318b095a Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 13 Sep 2017 14:13:46 +0200 Subject: [PATCH] EPUB export: add options dialog It just exposes the two options available at libepubgen level already. Change-Id: I428919ffe495b6d7ec2773f542e2fea6733d0a1c Reviewed-on: https://gerrit.libreoffice.org/42241 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- writerperfect/Library_wpftwriter.mk | 1 + writerperfect/UIConfig_writerperfect.mk | 1 + .../source/writer/EPUBExportDialog.cxx | 121 +++++++++++ .../source/writer/EPUBExportDialog.hxx | 41 ++++ .../source/writer/EPUBExportFilter.cxx | 14 +- .../source/writer/EPUBExportFilter.hxx | 5 + .../source/writer/EPUBExportUIComponent.cxx | 9 +- writerperfect/uiconfig/ui/exportepub.ui | 194 ++++++++++++++++++ 8 files changed, 383 insertions(+), 3 deletions(-) create mode 100644 writerperfect/source/writer/EPUBExportDialog.cxx create mode 100644 writerperfect/source/writer/EPUBExportDialog.hxx create mode 100644 writerperfect/uiconfig/ui/exportepub.ui diff --git a/writerperfect/Library_wpftwriter.mk b/writerperfect/Library_wpftwriter.mk index d3d2cc9a209b..bf605e718dc1 100644 --- a/writerperfect/Library_wpftwriter.mk +++ b/writerperfect/Library_wpftwriter.mk @@ -68,6 +68,7 @@ $(eval $(call gb_Library_use_externals,wpftwriter,\ $(eval $(call gb_Library_add_exception_objects,wpftwriter,\ writerperfect/source/writer/AbiWordImportFilter \ writerperfect/source/writer/EBookImportFilter \ + writerperfect/source/writer/EPUBExportDialog \ writerperfect/source/writer/EPUBExportFilter \ writerperfect/source/writer/EPUBExportUIComponent \ writerperfect/source/writer/EPUBPackage \ diff --git a/writerperfect/UIConfig_writerperfect.mk b/writerperfect/UIConfig_writerperfect.mk index d0d8ef5030fb..8599babf7bde 100644 --- a/writerperfect/UIConfig_writerperfect.mk +++ b/writerperfect/UIConfig_writerperfect.mk @@ -21,6 +21,7 @@ $(eval $(call gb_UIConfig_UIConfig,writerperfect)) $(eval $(call gb_UIConfig_add_uifiles,writerperfect,\ writerperfect/uiconfig/ui/wpftencodingdialog \ + writerperfect/uiconfig/ui/exportepub \ )) # vim: set noet sw=4 ts=4: diff --git a/writerperfect/source/writer/EPUBExportDialog.cxx b/writerperfect/source/writer/EPUBExportDialog.cxx new file mode 100644 index 000000000000..50bad98b4281 --- /dev/null +++ b/writerperfect/source/writer/EPUBExportDialog.cxx @@ -0,0 +1,121 @@ +/* -*- 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/. + */ + +#include "EPUBExportDialog.hxx" + +#include "EPUBExportFilter.hxx" + +using namespace com::sun::star; + +namespace +{ +/// Converts version value to a listbox entry position. +sal_Int32 VersionToPosition(sal_Int32 nVersion) +{ + sal_Int32 nPosition = 0; + + switch (nVersion) + { + case 30: + nPosition = 0; + break; + case 20: + nPosition = 1; + break; + default: + assert(false); + break; + } + + return nPosition; +} + +/// Converts listbox entry position to a version value. +sal_Int32 PositionToVersion(sal_Int32 nPosition) +{ + sal_Int32 nVersion = 0; + + switch (nPosition) + { + case 0: + nVersion = 30; + break; + case 1: + nVersion = 20; + break; + default: + assert(false); + break; + } + + return nVersion; +} +} + +namespace writerperfect +{ + +EPUBExportDialog::EPUBExportDialog(vcl::Window *pParent, comphelper::SequenceAsHashMap &rFilterData) + : ModalDialog(pParent, "EpubDialog", "writerperfect/ui/exportepub.ui"), + mrFilterData(rFilterData) +{ + get(m_pVersion, "versionlb"); + assert(PositionToVersion(m_pVersion->GetSelectEntryPos()) == EPUBExportFilter::GetDefaultVersion()); + + auto it = rFilterData.find("EPUBVersion"); + if (it != rFilterData.end()) + { + sal_Int32 nVersion = 0; + if (it->second >>= nVersion) + m_pVersion->SelectEntryPos(VersionToPosition(nVersion)); + } + m_pVersion->SetSelectHdl(LINK(this, EPUBExportDialog, VersionSelectHdl)); + + get(m_pSplit, "splitlb"); + it = rFilterData.find("EPUBSplitMethod"); + if (it != rFilterData.end()) + { + sal_Int32 nSplitMethod = 0; + if (it->second >>= nSplitMethod) + // No conversion, 1:1 mapping between libepubgen::EPUBSplitMethod + // and entry positions. + m_pVersion->SelectEntryPos(nSplitMethod); + } + else + m_pSplit->SelectEntryPos(EPUBExportFilter::GetDefaultSplitMethod()); + m_pSplit->SetSelectHdl(LINK(this, EPUBExportDialog, SplitSelectHdl)); +} + +IMPL_LINK_NOARG(EPUBExportDialog, VersionSelectHdl, ListBox &, void) +{ + mrFilterData["EPUBVersion"] <<= PositionToVersion(m_pVersion->GetSelectEntryPos()); +} + +IMPL_LINK_NOARG(EPUBExportDialog, SplitSelectHdl, ListBox &, void) +{ + // No conversion, 1:1 mapping between entry positions and + // libepubgen::EPUBSplitMethod. + mrFilterData["EPUBSplitMethod"] <<= m_pSplit->GetSelectEntryPos(); +} + +EPUBExportDialog::~EPUBExportDialog() +{ + disposeOnce(); +} + +void EPUBExportDialog::dispose() +{ + m_pVersion.clear(); + m_pSplit.clear(); + ModalDialog::dispose(); +} + +} // namespace writerperfect + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/EPUBExportDialog.hxx b/writerperfect/source/writer/EPUBExportDialog.hxx new file mode 100644 index 000000000000..bc8e2ed878ce --- /dev/null +++ b/writerperfect/source/writer/EPUBExportDialog.hxx @@ -0,0 +1,41 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_WRITERPERFECT_SOURCE_WRITER_EPUBEXPORTDIALOG_HXX +#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_EPUBEXPORTDIALOG_HXX + +#include +#include +#include + +namespace writerperfect +{ + +/// EPUB export options dialog. +class EPUBExportDialog : public ModalDialog +{ +public: + EPUBExportDialog(vcl::Window *pParent, comphelper::SequenceAsHashMap &rFilterData); + ~EPUBExportDialog() override; + void dispose() override; + +private: + DECL_LINK(VersionSelectHdl, ListBox &, void); + DECL_LINK(SplitSelectHdl, ListBox &, void); + + comphelper::SequenceAsHashMap &mrFilterData; + VclPtr m_pVersion; + VclPtr m_pSplit; +}; + +} // namespace writerperfect + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/source/writer/EPUBExportFilter.cxx b/writerperfect/source/writer/EPUBExportFilter.cxx index 778e6a4e51be..ef2ba333e55b 100644 --- a/writerperfect/source/writer/EPUBExportFilter.cxx +++ b/writerperfect/source/writer/EPUBExportFilter.cxx @@ -33,10 +33,20 @@ EPUBExportFilter::EPUBExportFilter(const uno::Reference { } +sal_Int32 EPUBExportFilter::GetDefaultVersion() +{ + return 30; +} + +sal_Int32 EPUBExportFilter::GetDefaultSplitMethod() +{ + return libepubgen::EPUB_SPLIT_METHOD_HEADING; +} + sal_Bool EPUBExportFilter::filter(const uno::Sequence &rDescriptor) { - sal_Int32 nVersion = 30; - sal_Int32 nSplitMethod = libepubgen::EPUB_SPLIT_METHOD_HEADING; + sal_Int32 nVersion = EPUBExportFilter::GetDefaultVersion(); + sal_Int32 nSplitMethod = EPUBExportFilter::GetDefaultSplitMethod(); uno::Sequence aFilterData; for (sal_Int32 i = 0; i < rDescriptor.getLength(); ++i) { diff --git a/writerperfect/source/writer/EPUBExportFilter.hxx b/writerperfect/source/writer/EPUBExportFilter.hxx index 10f39dcfbef4..b423f96175e7 100644 --- a/writerperfect/source/writer/EPUBExportFilter.hxx +++ b/writerperfect/source/writer/EPUBExportFilter.hxx @@ -45,6 +45,11 @@ public: OUString SAL_CALL getImplementationName() override; sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override; css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + + /// Gives the default EPUB version. + static sal_Int32 GetDefaultVersion(); + /// Gives the default split method. + static sal_Int32 GetDefaultSplitMethod(); }; } // namespace writerperfect diff --git a/writerperfect/source/writer/EPUBExportUIComponent.cxx b/writerperfect/source/writer/EPUBExportUIComponent.cxx index 40ecea56262d..0be6aacc1ca8 100644 --- a/writerperfect/source/writer/EPUBExportUIComponent.cxx +++ b/writerperfect/source/writer/EPUBExportUIComponent.cxx @@ -13,6 +13,10 @@ #include #include +#include +#include + +#include "EPUBExportDialog.hxx" using namespace com::sun::star; @@ -70,7 +74,10 @@ void EPUBExportUIComponent::setTitle(const OUString &/*rTitle*/) sal_Int16 EPUBExportUIComponent::execute() { - return ui::dialogs::ExecutableDialogResults::OK; + ScopedVclPtrInstance pDialog(Application::GetDefDialogParent(), maFilterData); + if (pDialog->Execute() == RET_OK) + return ui::dialogs::ExecutableDialogResults::OK; + return ui::dialogs::ExecutableDialogResults::CANCEL; } extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface *SAL_CALL com_sun_star_comp_Writer_EPUBExportUIComponent_get_implementation(uno::XComponentContext *pCtx, uno::Sequence const &) diff --git a/writerperfect/uiconfig/ui/exportepub.ui b/writerperfect/uiconfig/ui/exportepub.ui new file mode 100644 index 000000000000..20be5d41a52b --- /dev/null +++ b/writerperfect/uiconfig/ui/exportepub.ui @@ -0,0 +1,194 @@ + + + + + + False + 6 + EPUB Export + False + True + dialog + + + False + vertical + 12 + + + False + end + + + gtk-ok + True + True + True + True + True + True + + + False + True + 0 + + + + + gtk-cancel + True + True + True + True + + + False + True + 1 + + + + + gtk-help + True + True + True + True + + + False + True + 2 + True + + + + + False + True + end + 2 + + + + + True + False + 6 + 12 + + + True + False + vertical + 6 + + + True + False + 6 + Version: + True + versionlb + 0 + + + False + True + 3 + + + + + True + False + 0 + + EPUB 3.0 + EPUB 2.0 + + + + False + True + 4 + + + + + + + False + True + 0 + + + + + True + False + 6 + 12 + + + True + False + vertical + 6 + + + True + False + 6 + Split method: + True + versionlb + 0 + + + False + True + 3 + + + + + True + False + 0 + + Page break + Heading + + + + False + True + 4 + + + + + + + False + True + 1 + + + + + + ok + cancel + help + + + + 9999 + 1 + 1 + 10 + +