1
// Copyright (c) 2005, Rodrigo Braz Monteiro, Niels Martin Hansen
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
7
// * Redistributions of source code must retain the above copyright notice,
8
// this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright notice,
10
// this list of conditions and the following disclaimer in the documentation
11
// and/or other materials provided with the distribution.
12
// * Neither the name of the Aegisub Group nor the names of its contributors
13
// may be used to endorse or promote products derived from this software
14
// without specific prior written permission.
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
// POSSIBILITY OF SUCH DAMAGE.
28
// -----------------------------------------------------------------------------
32
// Website: http://aegisub.cellosoft.com
33
// Contact: mailto:zeratul@cellosoft.com
41
#include <wx/tokenzr.h>
42
#include <wx/button.h>
43
#include <wx/stattext.h>
44
#include <wx/filedlg.h>
45
#include <wx/msgdlg.h>
46
#include "dialog_export.h"
48
#include "ass_exporter.h"
49
#include "frame_main.h"
50
#include "help_button.h"
51
#include "include/aegisub/exception.h"
56
DialogExport::DialogExport (wxWindow *parent)
57
: wxDialog (parent, -1, _("Export"), wxDefaultPosition, wxSize(200,100), wxCAPTION | wxCLOSE_BOX, _T("Export"))
60
wxSizer *TopSizer = new wxStaticBoxSizer(wxVERTICAL,this,_("Filters"));
61
Export = new AssExporter(AssFile::top);
62
wxArrayString filters = Export->GetAllFilterNames();
63
FilterList = new wxCheckListBox(this, Filter_List_Box, wxDefaultPosition, wxSize(200,100), filters);
65
// Get selected filters
66
wxString selected = Export->GetOriginalSubs()->GetScriptInfo(_T("Export filters"));
67
wxStringTokenizer token(selected, _T("|"));
69
while (token.HasMoreTokens()) {
70
wxString cur = token.GetNextToken();
73
for (unsigned int i=0;i<FilterList->GetCount();i++) {
74
if (FilterList->GetString(i) == cur) {
82
// No filters listed on header, select all
84
for (unsigned int i=0;i<FilterList->GetCount();i++) {
90
wxSizer *TopButtons = new wxBoxSizer(wxHORIZONTAL);
91
TopButtons->Add(new wxButton(this,Button_Move_Up,_("Move up"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,0);
92
TopButtons->Add(new wxButton(this,Button_Move_Down,_("Move down"),wxDefaultPosition,wxSize(90,-1)),1,wxEXPAND | wxRIGHT,5);
93
TopButtons->Add(new wxButton(this,Button_Select_All,_("Select all"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
94
TopButtons->Add(new wxButton(this,Button_Select_None,_("Select none"),wxDefaultPosition,wxSize(80,-1)),1,wxEXPAND | wxRIGHT,0);
97
Description = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxSize(200,60), wxTE_MULTILINE | wxTE_READONLY);
99
// Charset dropdown list
100
wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
101
CharsetList = new wxChoice(this, Charset_List_Box, wxDefaultPosition, wxDefaultSize, FrameMain::GetEncodings());
102
wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
103
charset_list_sizer->Add(charset_list_label, 0, wxALIGN_CENTER | wxRIGHT, 5);
104
charset_list_sizer->Add(CharsetList, 1, wxEXPAND);
105
if (!CharsetList->SetStringSelection(Export->GetOriginalSubs()->GetScriptInfo(_T("Export Encoding")))) {
106
CharsetList->SetStringSelection(_T("UTF-8"));
110
TopSizer->Add(FilterList,1,wxEXPAND,0);
111
TopSizer->Add(TopButtons,0,wxEXPAND,0);
112
TopSizer->Add(Description,0,wxEXPAND | wxTOP,5);
113
TopSizer->Add(charset_list_sizer, 0, wxEXPAND | wxTOP, 5);
116
wxStdDialogButtonSizer *ButtonSizer = new wxStdDialogButtonSizer();
117
wxButton *process = new wxButton(this,Button_Process,_("Export..."));
118
ButtonSizer->AddButton(process);
119
ButtonSizer->AddButton(new wxButton(this,wxID_CANCEL));
120
ButtonSizer->AddButton(new HelpButton(this,_T("Export")));
121
ButtonSizer->SetAffirmativeButton(process);
122
ButtonSizer->Realize();
125
HorizSizer = new wxBoxSizer(wxHORIZONTAL);
126
OptionsSizer = new wxBoxSizer(wxVERTICAL);
127
Export->DrawSettings(this,OptionsSizer);
128
HorizSizer->Add(TopSizer,0,wxEXPAND | wxLEFT | wxTOP | wxBOTTOM,5);
129
HorizSizer->Add(OptionsSizer,1,wxEXPAND | wxTOP | wxRIGHT | wxBOTTOM,5);
132
MainSizer = new wxBoxSizer(wxVERTICAL);
133
MainSizer->Add(HorizSizer,1,wxEXPAND,0);
134
MainSizer->Add(ButtonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
135
MainSizer->SetSizeHints(this);
139
FilterList->SetFocus();
145
DialogExport::~DialogExport() {
146
// Set script info data
149
for (unsigned int i=0;i<FilterList->GetCount();i++) {
150
if (FilterList->IsChecked(i)) {
151
infoList += FilterList->GetString(i) + _T("|");
155
if (n > 0) infoList = infoList.Left(infoList.Length()-1);
156
Export->GetOriginalSubs()->SetScriptInfo(_T("Export filters"),infoList);
159
if (Export) delete Export;
164
/////////////////////////////////
165
// Refresh displaying of options
166
void DialogExport::RefreshOptions() {
167
int num = FilterList->GetCount();
168
for (int i=0;i<num;i++) {
169
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
170
if (sizer) OptionsSizer->Show(sizer,FilterList->IsChecked(i)?1:0,true);
173
MainSizer->Fit(this);
179
BEGIN_EVENT_TABLE(DialogExport,wxDialog)
180
EVT_BUTTON(Button_Process,DialogExport::OnProcess)
181
EVT_BUTTON(Button_Move_Up,DialogExport::OnMoveUp)
182
EVT_BUTTON(Button_Move_Down,DialogExport::OnMoveDown)
183
EVT_BUTTON(Button_Select_All,DialogExport::OnSelectAll)
184
EVT_BUTTON(Button_Select_None,DialogExport::OnSelectNone)
185
EVT_CHECKLISTBOX(Filter_List_Box,DialogExport::OnCheck)
186
EVT_LISTBOX(Filter_List_Box, DialogExport::OnChange)
192
void DialogExport::OnProcess(wxCommandEvent &event) {
194
wxString filename = wxFileSelector(_("Export subtitles file"),_T(""),_T(""),_T(""),AssFile::GetWildcardList(2),wxFD_SAVE | wxFD_OVERWRITE_PROMPT,this);
195
if (filename.empty()) return;
198
for (unsigned int i=0;i<FilterList->GetCount();i++) {
199
if (FilterList->IsChecked(i)) {
200
Export->AddFilter(FilterList->GetString(i));
207
Export->GetOriginalSubs()->SetScriptInfo(_T("Export Encoding"), CharsetList->GetStringSelection());
208
Export->Export(filename, CharsetList->GetStringSelection(), this);
210
catch (Aegisub::UserCancelException *) {
213
catch (const wchar_t *error) {
215
wxMessageBox(err, _T("Error exporting subtitles"), wxOK | wxICON_ERROR, this);
218
wxMessageBox(_T("Unknown error"), _T("Error exporting subtitles"), wxOK | wxICON_ERROR, this);
226
/////////////////////////////
227
// Checked or unchecked item
228
void DialogExport::OnCheck(wxCommandEvent &event) {
229
int n = event.GetInt();
230
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(n));
231
if (sizer) MainSizer->Show(sizer,FilterList->IsChecked(n)?1:0,true);
233
MainSizer->Fit(this);
239
void DialogExport::OnChange(wxCommandEvent &event) {
240
int n = FilterList->GetSelection();
241
if (n != wxNOT_FOUND) {
242
wxString name = FilterList->GetString(n);
243
//Description->SetValue(wxGetTranslation(Export->GetDescription(name)));
244
Description->SetValue(Export->GetDescription(name));
251
void DialogExport::OnMoveUp(wxCommandEvent &event) {
252
int pos = FilterList->GetSelection();
253
if (pos <= 0) return;
254
FilterList->Freeze();
255
wxString tempname = FilterList->GetString(pos);
256
bool tempval = FilterList->IsChecked(pos);
257
FilterList->SetString(pos,FilterList->GetString(pos-1));
258
FilterList->Check(pos,FilterList->IsChecked(pos-1));
259
FilterList->SetString(pos-1,tempname);
260
FilterList->Check(pos-1,tempval);
261
FilterList->SetSelection(pos-1);
268
void DialogExport::OnMoveDown(wxCommandEvent &event) {
269
int pos = FilterList->GetSelection();
270
int n = FilterList->GetCount();
271
if (pos == n-1 || pos == -1) return;
272
FilterList->Freeze();
273
wxString tempname = FilterList->GetString(pos);
274
bool tempval = FilterList->IsChecked(pos);
275
FilterList->SetString(pos,FilterList->GetString(pos+1));
276
FilterList->Check(pos,FilterList->IsChecked(pos+1));
277
FilterList->SetString(pos+1,tempname);
278
FilterList->Check(pos+1,tempval);
279
FilterList->SetSelection(pos+1);
286
void DialogExport::OnSelectAll(wxCommandEvent &event) {
288
FilterList->Freeze();
289
for (unsigned int i=0;i<FilterList->GetCount();i++) {
290
FilterList->Check(i,true);
291
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
292
if (sizer) MainSizer->Show(sizer,true,true);
297
MainSizer->Fit(this);
305
void DialogExport::OnSelectNone(wxCommandEvent &event) {
307
FilterList->Freeze();
308
for (unsigned int i=0;i<FilterList->GetCount();i++) {
309
FilterList->Check(i,false);
310
wxSizer *sizer = Export->GetSettingsSizer(FilterList->GetString(i));
311
if (sizer) MainSizer->Show(sizer,false,true);
318
MainSizer->Fit(this);