~ubuntu-branches/ubuntu/trusty/aegisub/trusty

« back to all changes in this revision

Viewing changes to src/ass_exporter.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel
  • Date: 2012-03-16 22:58:00 UTC
  • Revision ID: package-import@ubuntu.com-20120316225800-yfb8h9e5n04rk46a
Tags: upstream-2.1.9
ImportĀ upstreamĀ versionĀ 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2005, Rodrigo Braz Monteiro
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are met:
 
6
//
 
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.
 
15
//
 
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.
 
27
//
 
28
// -----------------------------------------------------------------------------
 
29
//
 
30
// AEGISUB
 
31
//
 
32
// Website: http://aegisub.cellosoft.com
 
33
// Contact: mailto:zeratul@cellosoft.com
 
34
//
 
35
 
 
36
 
 
37
///////////
 
38
// Headers
 
39
#include "config.h"
 
40
 
 
41
#include "ass_exporter.h"
 
42
#include "ass_export_filter.h"
 
43
#include "ass_file.h"
 
44
#include "frame_main.h"
 
45
 
 
46
 
 
47
///////////////
 
48
// Constructor
 
49
AssExporter::AssExporter (AssFile *subs) {
 
50
        OriginalSubs = subs;
 
51
        IsDefault = true;
 
52
}
 
53
 
 
54
 
 
55
//////////////
 
56
// Destructor
 
57
AssExporter::~AssExporter () {
 
58
}
 
59
 
 
60
 
 
61
/////////////////////////
 
62
// Draw control settings
 
63
void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
 
64
        IsDefault = false;
 
65
        wxWindow *window;
 
66
        wxSizer *box;
 
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);
 
74
                if (window) {
 
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;
 
79
                }
 
80
                else {
 
81
                        delete box;
 
82
                }
 
83
        }
 
84
}
 
85
 
 
86
 
 
87
///////////////////////
 
88
// Add filter to chain
 
89
void AssExporter::AddFilter(wxString name) {
 
90
        // Get filter
 
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) {
 
96
                        filter = *cur;
 
97
                }
 
98
        }
 
99
        
 
100
        // Check
 
101
        if (!filter) throw wxString::Format(_T("Filter not found: %s"), name.c_str());
 
102
 
 
103
        // Add to list
 
104
        Filters.push_back(filter);
 
105
}
 
106
 
 
107
 
 
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);
 
116
                }
 
117
        }
 
118
}
 
119
 
 
120
 
 
121
///////////////////////////
 
122
// Get name of all filters
 
123
wxArrayString AssExporter::GetAllFilterNames() {
 
124
        wxArrayString names;
 
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);
 
129
        }
 
130
        return names;
 
131
}
 
132
 
 
133
 
 
134
////////////////////////
 
135
// Transform for export
 
136
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
 
137
        // Copy
 
138
        AssFile *Subs = new AssFile(*OriginalSubs);
 
139
 
 
140
        // Run filters
 
141
        for (FilterList::iterator cur=Filters.begin();cur!=Filters.end();cur++) {
 
142
                (*cur)->LoadSettings(IsDefault);
 
143
                (*cur)->ProcessSubs(Subs, export_dialog);
 
144
        }
 
145
 
 
146
        // Done
 
147
        return Subs;
 
148
}
 
149
 
 
150
 
 
151
//////////
 
152
// Export
 
153
void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_dialog) {
 
154
        // Get transformation
 
155
        AssFile *Subs = ExportTransform(export_dialog);
 
156
 
 
157
        // Save
 
158
        Subs->Save(filename,false,false,charset);
 
159
        delete Subs;
 
160
}
 
161
 
 
162
 
 
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;
 
169
}
 
170
 
 
171
 
 
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();
 
180
                }
 
181
        }
 
182
        throw wxString::Format(_T("Filter not found: %s"), name.c_str());
 
183
}