LibreOffice Module writerperfect (master) 1
EPUBExportDialog.cxx
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
10#include "EPUBExportDialog.hxx"
11
12#include <libepubgen/libepubgen.h>
13
14#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
15#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
16#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp>
17#include <comphelper/lok.hxx>
20#include <sfx2/opengrf.hxx>
23
24#include "EPUBExportFilter.hxx"
25
26using namespace com::sun::star;
27
28namespace
29{
31sal_Int32 VersionToPosition(sal_Int32 nVersion)
32{
33 sal_Int32 nPosition = 0;
34
35 switch (nVersion)
36 {
37 case 30:
38 nPosition = 0;
39 break;
40 case 20:
41 nPosition = 1;
42 break;
43 default:
44 assert(false);
45 break;
46 }
47
48 return nPosition;
49}
50
52sal_Int32 PositionToVersion(sal_Int32 nPosition)
53{
54 sal_Int32 nVersion = 0;
55
56 switch (nPosition)
57 {
58 case 0:
59 nVersion = 30;
60 break;
61 case 1:
62 nVersion = 20;
63 break;
64 default:
65 assert(false);
66 break;
67 }
68
69 return nVersion;
70}
71}
72
73namespace writerperfect
74{
78 css::uno::Reference<css::lang::XComponent> xDocument)
79 : GenericDialogController(pParent, "writerperfect/ui/exportepub.ui", "EpubDialog")
80 , m_xContext(std::move(xContext))
81 , m_rFilterData(rFilterData)
82 , m_xSourceDocument(std::move(xDocument))
83 , m_xVersion(m_xBuilder->weld_combo_box("versionlb"))
84 , m_xSplit(m_xBuilder->weld_combo_box("splitlb"))
85 , m_xLayout(m_xBuilder->weld_combo_box("layoutlb"))
86 , m_xCoverPath(m_xBuilder->weld_entry("coverpath"))
87 , m_xCoverButton(m_xBuilder->weld_button("coverbutton"))
88 , m_xMediaDir(m_xBuilder->weld_entry("mediadir"))
89 , m_xMediaButton(m_xBuilder->weld_button("mediabutton"))
90 , m_xOKButton(m_xBuilder->weld_button("ok"))
91 , m_xIdentifier(m_xBuilder->weld_entry("identifier"))
92 , m_xTitle(m_xBuilder->weld_entry("title"))
93 , m_xInitialCreator(m_xBuilder->weld_entry("author"))
94 , m_xLanguage(m_xBuilder->weld_entry("language"))
95 , m_xDate(m_xBuilder->weld_entry("date"))
96 , m_xCustomizeFrame(m_xBuilder->weld_frame("customize"))
97
98{
99 assert(PositionToVersion(m_xVersion->get_active()) == EPUBExportFilter::GetDefaultVersion());
100
101 auto it = rFilterData.find("EPUBVersion");
102 if (it != rFilterData.end())
103 {
104 sal_Int32 nVersion = 0;
105 if (it->second >>= nVersion)
106 m_xVersion->set_active(VersionToPosition(nVersion));
107 }
108 m_xVersion->connect_changed(LINK(this, EPUBExportDialog, VersionSelectHdl));
109
110 it = rFilterData.find("EPUBSplitMethod");
111 if (it != rFilterData.end())
112 {
113 sal_Int32 nSplitMethod = 0;
114 if (it->second >>= nSplitMethod)
115 // No conversion, 1:1 mapping between libepubgen::EPUBSplitMethod
116 // and entry positions.
117 m_xSplit->set_active(nSplitMethod);
118 }
119 else
121 m_xSplit->connect_changed(LINK(this, EPUBExportDialog, SplitSelectHdl));
122
123 it = rFilterData.find("EPUBLayoutMethod");
124 if (it != rFilterData.end())
125 {
126 sal_Int32 nLayoutMethod = 0;
127 if (it->second >>= nLayoutMethod)
128 // No conversion, 1:1 mapping between libepubgen::EPUBLayoutMethod
129 // and entry positions.
130 m_xLayout->set_active(nLayoutMethod);
131 }
132 else
134 m_xLayout->connect_changed(LINK(this, EPUBExportDialog, LayoutSelectHdl));
135
136 m_xCoverButton->connect_clicked(LINK(this, EPUBExportDialog, CoverClickHdl));
137
138 m_xMediaButton->connect_clicked(LINK(this, EPUBExportDialog, MediaClickHdl));
139
142 if (xDPS.is())
143 xDP = xDPS->getDocumentProperties();
144 if (xDP.is())
145 {
146 m_xTitle->set_text(xDP->getTitle());
147 m_xInitialCreator->set_text(xDP->getAuthor());
148
149 OUString aLanguage(LanguageTag::convertToBcp47(xDP->getLanguage(), false));
150 m_xLanguage->set_text(aLanguage);
151
152 OUStringBuffer aBuffer;
153 util::DateTime aDate(xDP->getModificationDate());
154 sax::Converter::convertDateTime(aBuffer, aDate, nullptr, true);
155 m_xDate->set_text(aBuffer.makeStringAndClear());
156 }
157
158 m_xOKButton->connect_clicked(LINK(this, EPUBExportDialog, OKClickHdl));
159
161 m_xCustomizeFrame->hide();
162}
163
165{
166 m_rFilterData["EPUBVersion"] <<= PositionToVersion(m_xVersion->get_active());
167}
168
170{
171 // No conversion, 1:1 mapping between entry positions and
172 // libepubgen::EPUBSplitMethod.
173 m_rFilterData["EPUBSplitMethod"] <<= static_cast<sal_Int32>(m_xSplit->get_active());
174}
175
177{
178 // No conversion, 1:1 mapping between entry positions and
179 // libepubgen::EPUBLayoutMethod.
180 m_rFilterData["EPUBLayoutMethod"] <<= static_cast<sal_Int32>(m_xLayout->get_active());
181 m_xSplit->set_sensitive(m_xLayout->get_active() != libepubgen::EPUB_LAYOUT_METHOD_FIXED);
182}
183
185{
186 SvxOpenGraphicDialog aDlg("Import", m_xDialog.get());
187 aDlg.EnableLink(false);
188 if (aDlg.Execute() == ERRCODE_NONE)
189 m_xCoverPath->set_text(aDlg.GetPath());
190}
191
193{
196 if (xFolderPicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
197 return;
198
199 m_xMediaDir->set_text(xFolderPicker->getDirectory());
200}
201
203{
204 // General
205 if (!m_xCoverPath->get_text().isEmpty())
206 m_rFilterData["RVNGCoverImage"] <<= m_xCoverPath->get_text();
207 if (!m_xMediaDir->get_text().isEmpty())
208 m_rFilterData["RVNGMediaDir"] <<= m_xMediaDir->get_text();
209
210 // Metadata
211 if (!m_xIdentifier->get_text().isEmpty())
212 m_rFilterData["RVNGIdentifier"] <<= m_xIdentifier->get_text();
213 if (!m_xTitle->get_text().isEmpty())
214 m_rFilterData["RVNGTitle"] <<= m_xTitle->get_text();
215 if (!m_xInitialCreator->get_text().isEmpty())
216 m_rFilterData["RVNGInitialCreator"] <<= m_xInitialCreator->get_text();
217 if (!m_xLanguage->get_text().isEmpty())
218 m_rFilterData["RVNGLanguage"] <<= m_xLanguage->get_text();
219 if (!m_xDate->get_text().isEmpty())
220 m_rFilterData["RVNGDate"] <<= m_xDate->get_text();
221
222 m_xDialog->response(RET_OK);
223}
224
226
227} // namespace writerperfect
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
Reference< XExecutableDialog > m_xDialog
static OUString convertToBcp47(LanguageType nLangID)
OUString GetPath() const
iterator find(const OUString &rKey)
static void convertDateTime(OUStringBuffer &rBuffer, const css::util::DateTime &rDateTime, sal_Int16 const *pTimeZoneOffset, bool bAddTimeIf0AM=false)
EPUB export options dialog.
std::unique_ptr< weld::Entry > m_xTitle
std::unique_ptr< weld::Frame > m_xCustomizeFrame
std::unique_ptr< weld::Entry > m_xLanguage
std::unique_ptr< weld::ComboBox > m_xVersion
std::unique_ptr< weld::ComboBox > m_xSplit
std::unique_ptr< weld::Entry > m_xInitialCreator
std::unique_ptr< weld::ComboBox > m_xLayout
std::unique_ptr< weld::Button > m_xCoverButton
std::unique_ptr< weld::Button > m_xMediaButton
css::uno::Reference< css::lang::XComponent > m_xSourceDocument
EPUBExportDialog(weld::Window *pParent, comphelper::SequenceAsHashMap &rFilterData, css::uno::Reference< css::uno::XComponentContext > xContext, css::uno::Reference< css::lang::XComponent > xDocument)
std::unique_ptr< weld::Button > m_xOKButton
std::unique_ptr< weld::Entry > m_xDate
static sal_Int32 GetDefaultSplitMethod()
Gives the default split method.
static sal_Int32 GetDefaultVersion()
Gives the default EPUB version.
static sal_Int32 GetDefaultLayoutMethod()
Gives the default layout method.
#define ERRCODE_NONE
sal_Int16 nVersion
std::unique_ptr< weld::Button > m_xOKButton
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &rContext, weld::Window *pPreferredParent)
IMPL_LINK_NOARG(WPFTEncodingDialog, CancelHdl, weld::Button &, void)
RET_OK
std::unique_ptr< char[]> aBuffer