Aegisub/aegisub/src/ass_exporter.cpp

209 lines
5.6 KiB
C++
Raw Normal View History

2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, Rodrigo Braz Monteiro
// 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 Project http://www.aegisub.org/
2006-01-16 22:02:54 +01:00
//
// $Id$
/// @file ass_exporter.cpp
/// @brief Overall set-up and management of export operations
/// @ingroup export
///
2006-01-16 22:02:54 +01:00
///////////
// Headers
#include "config.h"
2006-01-16 22:02:54 +01:00
#include "ass_export_filter.h"
#include "ass_exporter.h"
2006-01-16 22:02:54 +01:00
#include "ass_file.h"
#include "frame_main.h"
/// @brief Constructor
/// @param subs
///
2006-01-16 22:02:54 +01:00
AssExporter::AssExporter (AssFile *subs) {
OriginalSubs = subs;
IsDefault = true;
}
/// @brief Destructor
///
2006-01-16 22:02:54 +01:00
AssExporter::~AssExporter () {
}
/// @brief Draw control settings
/// @param parent
/// @param AddTo
///
2006-01-16 22:02:54 +01:00
void AssExporter::DrawSettings(wxWindow *parent,wxSizer *AddTo) {
IsDefault = false;
wxWindow *window;
wxSizer *box;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
// Make sure to construct static box sizer first, so it won't overlap
// the controls on wxMac.
box = new wxStaticBoxSizer(wxVERTICAL,parent,(*cur)->RegisterName);
2006-01-16 22:02:54 +01:00
window = (*cur)->GetConfigDialogWindow(parent);
if (window) {
box->Add(window,0,wxEXPAND,0);
AddTo->Add(box,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
AddTo->Show(box,false);
Sizers[(*cur)->RegisterName] = box;
}
else {
delete box;
}
2006-01-16 22:02:54 +01:00
}
}
/// @brief Add filter to chain
/// @param name
///
2006-01-16 22:02:54 +01:00
void AssExporter::AddFilter(wxString name) {
// Get filter
AssExportFilter *filter = NULL;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->RegisterName == name) {
filter = *cur;
}
}
// Check
if (!filter) throw wxString::Format(_T("Filter not found: %s"), name.c_str());
2006-01-16 22:02:54 +01:00
// Add to list
Filters.push_back(filter);
}
/// @brief Adds all autoexporting filters to chain
///
2006-01-16 22:02:54 +01:00
void AssExporter::AddAutoFilters() {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->autoExporter) {
Filters.push_back(*cur);
}
}
}
/// @brief Get name of all filters
/// @return
///
2006-01-16 22:02:54 +01:00
wxArrayString AssExporter::GetAllFilterNames() {
wxArrayString names;
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if (!(*cur)->hidden) names.Add((*cur)->RegisterName);
2006-01-16 22:02:54 +01:00
}
return names;
}
/// @brief Transform for export
/// @param export_dialog
/// @return
///
AssFile *AssExporter::ExportTransform(wxWindow *export_dialog) {
2006-01-16 22:02:54 +01:00
// Copy
AssFile *Subs = new AssFile(*OriginalSubs);
// Run filters
for (FilterList::iterator cur=Filters.begin();cur!=Filters.end();cur++) {
(*cur)->LoadSettings(IsDefault);
(*cur)->ProcessSubs(Subs, export_dialog);
2006-01-16 22:02:54 +01:00
}
// Done
return Subs;
}
/// @brief Export
/// @param filename
/// @param charset
/// @param export_dialog
///
void AssExporter::Export(wxString filename, wxString charset, wxWindow *export_dialog) {
// Get transformation
AssFile *Subs = ExportTransform(export_dialog);
2006-01-16 22:02:54 +01:00
// Save
Subs->Save(filename,false,false,charset);
delete Subs;
}
/// @brief Get window associated with name
/// @param name
/// @return
///
2006-01-16 22:02:54 +01:00
wxSizer *AssExporter::GetSettingsSizer(wxString name) {
SizerMap::iterator pos = Sizers.find(name);
if (pos == Sizers.end()) return NULL;
else return pos->second;
}
/// @brief Get description of filter
/// @param name
///
2006-01-16 22:02:54 +01:00
wxString AssExporter::GetDescription(wxString name) {
FilterList::iterator begin = AssExportFilterChain::GetFilterList()->begin();
FilterList::iterator end = AssExportFilterChain::GetFilterList()->end();
for (FilterList::iterator cur=begin;cur!=end;cur++) {
if ((*cur)->RegisterName == name) {
return (*cur)->GetDescription();
2006-01-16 22:02:54 +01:00
}
}
throw wxString::Format(_T("Filter not found: %s"), name.c_str());
2006-01-16 22:02:54 +01:00
}