forked from Aegisub/Aegisub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog_export.cpp
302 lines (264 loc) · 9.94 KB
/
dialog_export.cpp
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// Copyright (c) 2005, Rodrigo Braz Monteiro, Niels Martin Hansen
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:[email protected]
//
///////////
// Headers
#include <wx/tokenzr.h>
#include "dialog_export.h"
#include "ass_file.h"
#include "ass_exporter.h"
#include "frame_main.h"
///////////////
// Constructor
DialogExport::DialogExport (wxWindow *parent)
: wxDialog (parent, -1, _("Export"), wxDefaultPosition, wxSize(200,100), wxCAPTION | wxCLOSE_BOX, _T("Export"))
{
// Filter list
Export = new AssExporter(AssFile::top);
wxArrayString filters = Export->GetAllFilterNames();
FilterList = new wxCheckListBox(this, Filter_List_Box, wxDefaultPosition, wxSize(200,100), filters);
// Get selected filters
wxString selected = Export->GetOriginalSubs()->GetScriptInfo(_T("Export filters"));
wxStringTokenizer token(selected, _T("|"));
int n = 0;
while (token.HasMoreTokens()) {
wxString cur = token.GetNextToken();
if (!cur.IsEmpty()) {
n++;
for (int i=0;i<FilterList->GetCount();i++) {
if (FilterList->GetString(i) == cur) {
FilterList->Check(i);
break;
}
}
}
}
// No filters listed on header, select all
if (n == 0) {
for (int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i);
}
}
// Top buttons
wxSizer *TopButtons = new wxBoxSizer(wxHORIZONTAL);
TopButtons->Add(new wxButton(this,Button_Move_Up,_("Move up"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,0);
TopButtons->Add(new wxButton(this,Button_Move_Down,_("Move down"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,5);
TopButtons->Add(new wxButton(this,Button_Select_All,_("Select all"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
TopButtons->Add(new wxButton(this,Button_Select_None,_("Select none"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
// Charset dropdown list
wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
CharsetList = new wxChoice(this, Charset_List_Box, wxDefaultPosition, wxDefaultSize, FrameMain::GetEncodings());
wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
charset_list_sizer->Add(charset_list_label, 0, wxALIGN_CENTER | wxRIGHT, 5);
charset_list_sizer->Add(CharsetList, 1, wxEXPAND);
if (!CharsetList->SetStringSelection(Export->GetOriginalSubs()->GetScriptInfo(_T("Export Encoding")))) {
CharsetList->SetStringSelection(_T("UTF-8"));
}
// Top sizer
wxSizer *TopSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Filters"));
Description = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxSize(200,60), wxTE_MULTILINE | wxTE_READONLY);
TopSizer->Add(FilterList,1,wxEXPAND,0);
TopSizer->Add(TopButtons,0,wxEXPAND,0);
TopSizer->Add(Description,0,wxEXPAND | wxTOP,5);
TopSizer->Add(charset_list_sizer, 0, wxEXPAND | wxTOP, 5);
// Button sizer
wxSizer *ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
ButtonSizer->AddStretchSpacer(1);
ButtonSizer->Add(new wxButton(this,Button_Process,_("Export...")),0,wxRIGHT,5);
ButtonSizer->Add(new wxButton(this,wxID_CANCEL),0,wxRIGHT,0);
// Draw stuff sizer
HorizSizer = new wxBoxSizer(wxHORIZONTAL);
OptionsSizer = new wxBoxSizer(wxVERTICAL);
Export->DrawSettings(this,OptionsSizer);
HorizSizer->Add(TopSizer,0,wxEXPAND | wxLEFT | wxTOP | wxBOTTOM,5);
HorizSizer->Add(OptionsSizer,1,wxEXPAND | wxTOP | wxRIGHT | wxBOTTOM,5);
// Main sizer
MainSizer = new wxBoxSizer(wxVERTICAL);
MainSizer->Add(HorizSizer,1,wxEXPAND,0);
MainSizer->Add(ButtonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
MainSizer->SetSizeHints(this);
SetSizer(MainSizer);
RefreshOptions();
CenterOnParent();
}
//////////////
// Destructor
DialogExport::~DialogExport() {
// Set script info data
int n = 0;
wxString infoList;
for (int i=0;i<FilterList->GetCount();i++) {
if (FilterList->IsChecked(i)) {
infoList += FilterList->GetString(i) + _T("|");
n++;
}
}
if (n > 0) infoList = infoList.Left(infoList.Length()-1);
Export->GetOriginalSubs()->SetScriptInfo(_T("Export filters"),infoList);
// Delete exporter
if (Export) delete Export;
Export = NULL;
}
/////////////////////////////////
// Refresh displaying of options
void DialogExport::RefreshOptions() {
int num = FilterList->GetCount();
for (int i=0;i<num;i++) {
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) OptionsSizer->Show(sizer,FilterList->IsChecked(i)?1:0,true);
}
Layout();
MainSizer->Fit(this);
}
///////////////
// Event table
BEGIN_EVENT_TABLE(DialogExport,wxDialog)
EVT_BUTTON(Button_Process,DialogExport::OnProcess)
EVT_BUTTON(Button_Move_Up,DialogExport::OnMoveUp)
EVT_BUTTON(Button_Move_Down,DialogExport::OnMoveDown)
EVT_BUTTON(Button_Select_All,DialogExport::OnSelectAll)
EVT_BUTTON(Button_Select_None,DialogExport::OnSelectNone)
EVT_CHECKLISTBOX(Filter_List_Box,DialogExport::OnCheck)
EVT_LISTBOX(Filter_List_Box, DialogExport::OnChange)
END_EVENT_TABLE()
/////////////////
// Process start
void DialogExport::OnProcess(wxCommandEvent &event) {
// Get destination
wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),_T("All Supported Types (*.ass,*.ssa,*.srt,*.prs)|*.ass;*.ssa;*.srt;*.prs|Advanced Substation Alpha (*.ass)|*.ass|Substation Alpha (*.ssa)|*.ssa|SubRip (*.srt)|*.srt|Pre-Rendered Subtitles (*.prs)|*.prs"),wxSAVE | wxOVERWRITE_PROMPT, this);
if (filename.empty()) return;
// Add filters
for (int i=0;i<FilterList->GetCount();i++) {
if (FilterList->IsChecked(i)) {
Export->AddFilter(FilterList->GetString(i));
}
}
// Export
try {
wxBusyCursor busy;
Export->GetOriginalSubs()->SetScriptInfo(_T("Export Encoding"), CharsetList->GetStringSelection());
Export->Export(filename, CharsetList->GetStringSelection(), this);
}
catch (const wchar_t *error) {
wxString err(error);
wxMessageBox(err, _T("Error exporting subtitles"), wxOK | wxICON_ERROR, this);
}
catch (...) {
wxMessageBox(_T("Unknown error"), _T("Error exporting subtitles"), wxOK | wxICON_ERROR, this);
}
// Close dialog
EndModal(0);
}
/////////////////////////////
// Checked or unchecked item
void DialogExport::OnCheck(wxCommandEvent &event) {
int n = event.GetInt();
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(n));
if (sizer) MainSizer->Show(sizer,FilterList->IsChecked(n)?1:0,true);
Layout();
MainSizer->Fit(this);
}
////////////////
// Changed item
void DialogExport::OnChange(wxCommandEvent &event) {
int n = FilterList->GetSelection();
if (n != wxNOT_FOUND) {
wxString name = FilterList->GetString(n);
//Description->SetValue(wxGetTranslation(Export->GetDescription(name)));
Description->SetValue(Export->GetDescription(name));
}
}
///////////
// Move up
void DialogExport::OnMoveUp(wxCommandEvent &event) {
int pos = FilterList->GetSelection();
if (pos <= 0) return;
FilterList->Freeze();
wxString tempname = FilterList->GetString(pos);
bool tempval = FilterList->IsChecked(pos);
FilterList->SetString(pos,FilterList->GetString(pos-1));
FilterList->Check(pos,FilterList->IsChecked(pos-1));
FilterList->SetString(pos-1,tempname);
FilterList->Check(pos-1,tempval);
FilterList->SetSelection(pos-1);
FilterList->Thaw();
}
/////////////
// Move down
void DialogExport::OnMoveDown(wxCommandEvent &event) {
int pos = FilterList->GetSelection();
int n = FilterList->GetCount();
if (pos == n-1 || pos == -1) return;
FilterList->Freeze();
wxString tempname = FilterList->GetString(pos);
bool tempval = FilterList->IsChecked(pos);
FilterList->SetString(pos,FilterList->GetString(pos+1));
FilterList->Check(pos,FilterList->IsChecked(pos+1));
FilterList->SetString(pos+1,tempname);
FilterList->Check(pos+1,tempval);
FilterList->SetSelection(pos+1);
FilterList->Thaw();
}
//////////////
// Select all
void DialogExport::OnSelectAll(wxCommandEvent &event) {
Freeze();
FilterList->Freeze();
for (int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i,true);
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) MainSizer->Show(sizer,true,true);
}
// Update dialog
Layout();
MainSizer->Fit(this);
FilterList->Thaw();
Thaw();
}
///////////////
// Select none
void DialogExport::OnSelectNone(wxCommandEvent &event) {
Freeze();
FilterList->Freeze();
for (int i=0;i<FilterList->GetCount();i++) {
FilterList->Check(i,false);
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
if (sizer) MainSizer->Show(sizer,false,true);
}
// Update dialog
FilterList->Thaw();
Thaw();
Layout();
MainSizer->Fit(this);
}