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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file ass_exporter.cpp
|
|
|
|
/// @brief Overall set-up and management of export operations
|
|
|
|
/// @ingroup export
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_exporter.h"
|
2013-01-04 16:01:50 +01:00
|
|
|
|
|
|
|
#include "ass_export_filter.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_file.h"
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "compat.h"
|
2011-09-28 21:46:53 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "project.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subtitle_format.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <wx/sizer.h>
|
2011-11-07 05:14:09 +01:00
|
|
|
|
2013-12-12 01:29:48 +01:00
|
|
|
AssExporter::AssExporter(agi::Context *c) : c(c) { }
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
void AssExporter::DrawSettings(wxWindow *parent, wxSizer *target_sizer) {
|
|
|
|
is_default = false;
|
2013-06-08 06:19:40 +02:00
|
|
|
for (auto& filter : *AssExportFilterChain::GetFilterList()) {
|
2007-09-24 19:40:03 +02:00
|
|
|
// Make sure to construct static box sizer first, so it won't overlap
|
|
|
|
// the controls on wxMac.
|
2014-05-22 01:23:28 +02:00
|
|
|
auto box = new wxStaticBoxSizer(wxVERTICAL, parent, to_wx(filter.GetName()));
|
2013-06-08 06:19:40 +02:00
|
|
|
wxWindow *window = filter.GetConfigDialogWindow(parent, c);
|
2006-01-16 22:02:54 +01:00
|
|
|
if (window) {
|
2011-09-28 21:46:41 +02:00
|
|
|
box->Add(window, 0, wxEXPAND, 0);
|
|
|
|
target_sizer->Add(box, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
|
|
|
|
target_sizer->Show(box, false);
|
2013-06-08 06:19:40 +02:00
|
|
|
Sizers[filter.GetName()] = box;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2007-09-24 19:40:03 +02:00
|
|
|
else {
|
|
|
|
delete box;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void AssExporter::AddFilter(std::string const& name) {
|
2013-06-08 06:19:40 +02:00
|
|
|
auto filter = AssExportFilterChain::GetFilter(name);
|
2014-06-11 00:28:45 +02:00
|
|
|
if (!filter) throw agi::InternalError("Filter not found: " + name);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-09-28 21:46:41 +02:00
|
|
|
filters.push_back(filter);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> AssExporter::GetAllFilterNames() const {
|
|
|
|
std::vector<std::string> names;
|
2013-06-08 06:19:40 +02:00
|
|
|
for (auto& filter : *AssExportFilterChain::GetFilterList())
|
|
|
|
names.emplace_back(filter.GetName());
|
2006-01-16 22:02:54 +01:00
|
|
|
return names;
|
|
|
|
}
|
|
|
|
|
2013-06-08 06:19:40 +02:00
|
|
|
void AssExporter::Export(agi::fs::path const& filename, std::string const& charset, wxWindow *export_dialog) {
|
|
|
|
AssFile subs(*c->ass);
|
2011-09-28 21:46:41 +02:00
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto filter : filters) {
|
|
|
|
filter->LoadSettings(is_default, c);
|
2013-06-08 06:19:40 +02:00
|
|
|
filter->ProcessSubs(&subs, export_dialog);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:57:46 +01:00
|
|
|
const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename);
|
|
|
|
if (!writer)
|
2014-06-11 00:28:45 +02:00
|
|
|
throw agi::InvalidInputException("Unknown file type.");
|
2013-01-26 02:57:46 +01:00
|
|
|
|
2014-09-19 20:47:34 +02:00
|
|
|
writer->ExportFile(&subs, filename, c->project->Timecodes(), charset);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
wxSizer *AssExporter::GetSettingsSizer(std::string const& name) {
|
2012-12-23 00:35:13 +01:00
|
|
|
auto pos = Sizers.find(name);
|
|
|
|
return pos == Sizers.end() ? nullptr : pos->second;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string const& AssExporter::GetDescription(std::string const& name) const {
|
2013-06-08 06:19:40 +02:00
|
|
|
auto filter = AssExportFilterChain::GetFilter(name);
|
2011-09-28 21:46:41 +02:00
|
|
|
if (filter)
|
|
|
|
return filter->GetDescription();
|
2014-06-11 00:28:45 +02:00
|
|
|
throw agi::InternalError("Filter not found: " + name);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|