1
// Copyright (c) 2005, Rodrigo Braz Monteiro
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 "ass_exporter.h"
42
#include "ass_export_filter.h"
44
#include "frame_main.h"
49
AssExporter::AssExporter (AssFile *subs) {
57
AssExporter::~AssExporter () {
61
/////////////////////////
62
// Draw control settings
63
void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
67
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
68
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
69
for (FilterList::iterator cur=begin;cur!=end;cur++) {
70
// Make sure to construct static box sizer first, so it won't overlap
71
// the controls on wxMac.
72
box = new wxStaticBoxSizer(wxVERTICAL,parent,(*cur)->RegisterName);
73
window = (*cur)->GetConfigDialogWindow(parent);
75
box->Add(window,0,wxEXPAND,0);
76
AddTo->Add(box,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
77
AddTo->Show(box,false);
78
Sizers[(*cur)->RegisterName] = box;
87
///////////////////////
88
// Add filter to chain
89
void AssExporter::AddFilter(wxString name) {
91
AssExportFilter *filter = NULL;
92
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
93
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
94
for (FilterList::iterator cur=begin;cur!=end;cur++) {
95
if ((*cur)->RegisterName == name) {
101
if (!filter) throw wxString::Format(_T("Filter not found: %s"), name.c_str());
104
Filters.push_back(filter);
108
///////////////////////////////////////////
109
// Adds all autoexporting filters to chain
110
void AssExporter::AddAutoFilters() {
111
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
112
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
113
for (FilterList::iterator cur=begin;cur!=end;cur++) {
114
if ((*cur)->autoExporter) {
115
Filters.push_back(*cur);
121
///////////////////////////
122
// Get name of all filters
123
wxArrayString AssExporter::GetAllFilterNames() {
125
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
126
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
127
for (FilterList::iterator cur=begin;cur!=end;cur++) {
128
if (!(*cur)->hidden) names.Add((*cur)->RegisterName);
134
////////////////////////
135
// Transform for export
136
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
138
AssFile *Subs = new AssFile(*OriginalSubs);
141
for (FilterList::iterator cur=Filters.begin();cur!=Filters.end();cur++) {
142
(*cur)->LoadSettings(IsDefault);
143
(*cur)->ProcessSubs(Subs, export_dialog);
153
void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_dialog) {
154
// Get transformation
155
AssFile *Subs = ExportTransform(export_dialog);
158
Subs->Save(filename,false,false,charset);
163
///////////////////////////////////
164
// Get window associated with name
165
wxSizer *AssExporter::GetSettingsSizer(wxString name) {
166
SizerMap::iterator pos = Sizers.find(name);
167
if (pos == Sizers.end()) return NULL;
168
else return pos->second;
172
/////////////////////////////
173
// Get description of filter
174
wxString AssExporter::GetDescription(wxString name) {
175
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
176
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
177
for (FilterList::iterator cur=begin;cur!=end;cur++) {
178
if ((*cur)->RegisterName == name) {
179
return (*cur)->GetDescription();
182
throw wxString::Format(_T("Filter not found: %s"), name.c_str());