1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/* -*- 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 <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <com/sun/star/ui/dialogs/FolderPicker.hpp>
#include <sfx2/opengrf.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, const uno::Reference<uno::XComponentContext> &xContext)
: ModalDialog(pParent, "EpubDialog", "writerperfect/ui/exportepub.ui"),
mxContext(xContext),
mrFilterData(rFilterData)
{
get(m_pVersion, "versionlb");
assert(PositionToVersion(m_pVersion->GetSelectedEntryPos()) == 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_pSplit->SelectEntryPos(nSplitMethod);
}
else
m_pSplit->SelectEntryPos(EPUBExportFilter::GetDefaultSplitMethod());
m_pSplit->SetSelectHdl(LINK(this, EPUBExportDialog, SplitSelectHdl));
get(m_pLayout, "layoutlb");
it = rFilterData.find("EPUBLayoutMethod");
if (it != rFilterData.end())
{
sal_Int32 nLayoutMethod = 0;
if (it->second >>= nLayoutMethod)
// No conversion, 1:1 mapping between libepubgen::EPUBLayoutMethod
// and entry positions.
m_pLayout->SelectEntryPos(nLayoutMethod);
}
else
m_pLayout->SelectEntryPos(EPUBExportFilter::GetDefaultLayoutMethod());
m_pLayout->SetSelectHdl(LINK(this, EPUBExportDialog, LayoutSelectHdl));
get(m_pCoverPath, "coverpath");
get(m_pCoverButton, "coverbutton");
m_pCoverButton->SetClickHdl(LINK(this, EPUBExportDialog, CoverClickHdl));
get(m_pMediaDir, "mediadir");
get(m_pMediaButton, "mediabutton");
m_pMediaButton->SetClickHdl(LINK(this, EPUBExportDialog, MediaClickHdl));
get(m_pIdentifier, "identifier");
get(m_pTitle, "title");
get(m_pInitialCreator, "author");
get(m_pLanguage, "language");
get(m_pDate, "date");
get(m_pOKButton, "ok");
m_pOKButton->SetClickHdl(LINK(this, EPUBExportDialog, OKClickHdl));
}
IMPL_LINK_NOARG(EPUBExportDialog, VersionSelectHdl, ListBox &, void)
{
mrFilterData["EPUBVersion"] <<= PositionToVersion(m_pVersion->GetSelectedEntryPos());
}
IMPL_LINK_NOARG(EPUBExportDialog, SplitSelectHdl, ListBox &, void)
{
// No conversion, 1:1 mapping between entry positions and
// libepubgen::EPUBSplitMethod.
mrFilterData["EPUBSplitMethod"] <<= m_pSplit->GetSelectedEntryPos();
}
IMPL_LINK_NOARG(EPUBExportDialog, LayoutSelectHdl, ListBox &, void)
{
// No conversion, 1:1 mapping between entry positions and
// libepubgen::EPUBLayoutMethod.
mrFilterData["EPUBLayoutMethod"] <<= m_pLayout->GetSelectedEntryPos();
}
IMPL_LINK_NOARG(EPUBExportDialog, CoverClickHdl, Button *, void)
{
SvxOpenGraphicDialog aDlg("Import", this);
aDlg.EnableLink(false);
if (aDlg.Execute() == ERRCODE_NONE)
m_pCoverPath->SetText(aDlg.GetPath());
}
IMPL_LINK_NOARG(EPUBExportDialog, MediaClickHdl, Button *, void)
{
uno::Reference<ui::dialogs::XFolderPicker2> xFolderPicker = ui::dialogs::FolderPicker::create(mxContext);
if (xFolderPicker->execute() != ui::dialogs::ExecutableDialogResults::OK)
return;
m_pMediaDir->SetText(xFolderPicker->getDirectory());
}
IMPL_LINK_NOARG(EPUBExportDialog, OKClickHdl, Button *, void)
{
// General
if (!m_pCoverPath->GetText().isEmpty())
mrFilterData["RVNGCoverImage"] <<= m_pCoverPath->GetText();
if (!m_pMediaDir->GetText().isEmpty())
mrFilterData["RVNGMediaDir"] <<= m_pMediaDir->GetText();
// Metadata
if (!m_pIdentifier->GetText().isEmpty())
mrFilterData["RVNGIdentifier"] <<= m_pIdentifier->GetText();
if (!m_pTitle->GetText().isEmpty())
mrFilterData["RVNGTitle"] <<= m_pTitle->GetText();
if (!m_pInitialCreator->GetText().isEmpty())
mrFilterData["RVNGInitialCreator"] <<= m_pInitialCreator->GetText();
if (!m_pLanguage->GetText().isEmpty())
mrFilterData["RVNGLanguage"] <<= m_pLanguage->GetText();
if (!m_pDate->GetText().isEmpty())
mrFilterData["RVNGDate"] <<= m_pDate->GetText();
EndDialog(RET_OK);
}
EPUBExportDialog::~EPUBExportDialog()
{
disposeOnce();
}
void EPUBExportDialog::dispose()
{
m_pVersion.clear();
m_pSplit.clear();
m_pCoverPath.clear();
m_pCoverButton.clear();
m_pOKButton.clear();
m_pIdentifier.clear();
m_pTitle.clear();
m_pInitialCreator.clear();
m_pLanguage.clear();
m_pDate.clear();
m_pMediaDir.clear();
m_pMediaButton.clear();
m_pLayout.clear();
ModalDialog::dispose();
}
} // namespace writerperfect
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|