2006-02-26 23:45:34 +01:00
|
|
|
// Copyright (c) 2006, 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 subtitle_format.cpp
|
|
|
|
/// @brief Base class for subtitle format handlers
|
|
|
|
/// @ingroup subtitle_io
|
|
|
|
///
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-03-29 01:58:40 +02:00
|
|
|
#include "subtitle_format.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/intl.h>
|
2009-09-11 00:48:29 +02:00
|
|
|
#include <wx/choicdlg.h> // Keep this last so wxUSE_CHOICEDLG is set.
|
2009-09-10 15:06:40 +02:00
|
|
|
|
2012-03-29 01:58:40 +02:00
|
|
|
#include "ass_attachment.h"
|
2011-09-28 21:44:53 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2012-03-29 01:58:40 +02:00
|
|
|
#include "ass_style.h"
|
2013-01-04 16:01:50 +01:00
|
|
|
#include "compat.h"
|
2006-02-27 01:06:46 +01:00
|
|
|
#include "subtitle_format_ass.h"
|
2012-03-29 21:05:26 +02:00
|
|
|
#include "subtitle_format_ebu3264.h"
|
2007-06-19 07:04:15 +02:00
|
|
|
#include "subtitle_format_encore.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitle_format_microdvd.h"
|
|
|
|
#include "subtitle_format_mkv.h"
|
|
|
|
#include "subtitle_format_srt.h"
|
2008-07-18 03:36:20 +02:00
|
|
|
#include "subtitle_format_transtation.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitle_format_ttxt.h"
|
|
|
|
#include "subtitle_format_txt.h"
|
2011-09-28 21:44:53 +02:00
|
|
|
#include "utils.h"
|
2010-07-08 06:29:04 +02:00
|
|
|
#include "video_context.h"
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs.h>
|
2012-11-05 17:20:58 +01:00
|
|
|
#include <libaegisub/of_type_adaptor.h>
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/algorithm/string/join.hpp>
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
#include <boost/algorithm/string/replace.hpp>
|
|
|
|
|
2012-09-25 01:35:27 +02:00
|
|
|
using namespace std::placeholders;
|
2006-02-26 23:45:34 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
SubtitleFormat::SubtitleFormat(std::string const& name)
|
2011-09-28 21:44:53 +02:00
|
|
|
: name(name)
|
|
|
|
{
|
|
|
|
formats.push_back(this);
|
2006-02-26 23:45:34 +01:00
|
|
|
}
|
|
|
|
|
2011-09-28 21:44:53 +02:00
|
|
|
SubtitleFormat::~SubtitleFormat() {
|
2012-11-28 16:46:33 +01:00
|
|
|
formats.erase(remove(begin(formats), end(formats), this));
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2013-10-05 15:58:15 +02:00
|
|
|
bool SubtitleFormat::CanReadFile(agi::fs::path const& filename, std::string const&) const {
|
2013-01-04 16:01:50 +01:00
|
|
|
auto wildcards = GetReadWildcards();
|
|
|
|
return any_of(begin(wildcards), end(wildcards),
|
|
|
|
[&](std::string const& ext) { return agi::fs::HasExtension(filename, ext); });
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
bool SubtitleFormat::CanWriteFile(agi::fs::path const& filename) const {
|
|
|
|
auto wildcards = GetWriteWildcards();
|
|
|
|
return any_of(begin(wildcards), end(wildcards),
|
|
|
|
[&](std::string const& ext) { return agi::fs::HasExtension(filename, ext); });
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
2012-03-29 01:58:40 +02:00
|
|
|
bool SubtitleFormat::CanSave(const AssFile *subs) const {
|
|
|
|
AssStyle defstyle;
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& line : subs->Line) {
|
2012-03-29 01:58:40 +02:00
|
|
|
// Check style, if anything non-default is found, return false
|
2012-11-04 04:53:03 +01:00
|
|
|
if (const AssStyle *curstyle = dynamic_cast<const AssStyle*>(&line)) {
|
2012-03-29 01:58:40 +02:00
|
|
|
if (curstyle->GetEntryData() != defstyle.GetEntryData())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for attachments, if any is found, return false
|
2012-11-04 04:53:03 +01:00
|
|
|
if (dynamic_cast<const AssAttachment*>(&line)) return false;
|
2012-03-29 01:58:40 +02:00
|
|
|
|
|
|
|
// Check dialog
|
2012-11-04 04:53:03 +01:00
|
|
|
if (const AssDialogue *curdiag = dynamic_cast<const AssDialogue*>(&line)) {
|
2012-03-29 01:58:40 +02:00
|
|
|
if (curdiag->GetStrippedText() != curdiag->Text)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-29 21:05:26 +02:00
|
|
|
agi::vfr::Framerate SubtitleFormat::AskForFPS(bool allow_vfr, bool show_smpte) {
|
2007-06-18 06:03:58 +02:00
|
|
|
wxArrayString choices;
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2007-06-18 06:03:58 +02:00
|
|
|
// Video FPS
|
2010-07-08 06:29:04 +02:00
|
|
|
VideoContext *context = VideoContext::Get();
|
|
|
|
bool vidLoaded = context->TimecodesLoaded();
|
2007-06-18 06:03:58 +02:00
|
|
|
if (vidLoaded) {
|
2012-03-29 21:04:36 +02:00
|
|
|
if (!context->FPS().IsVFR())
|
|
|
|
choices.Add(wxString::Format(_("From video (%g)"), context->FPS().FPS()));
|
|
|
|
else if (allow_vfr)
|
|
|
|
choices.Add(_("From video (VFR)"));
|
2011-12-22 22:27:53 +01:00
|
|
|
else
|
2012-03-29 21:04:36 +02:00
|
|
|
vidLoaded = false;
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2007-06-18 06:03:58 +02:00
|
|
|
// Standard FPS values
|
2009-05-13 22:24:21 +02:00
|
|
|
choices.Add(_("15.000 FPS"));
|
|
|
|
choices.Add(_("23.976 FPS (Decimated NTSC)"));
|
|
|
|
choices.Add(_("24.000 FPS (FILM)"));
|
2007-06-18 06:03:58 +02:00
|
|
|
choices.Add(_("25.000 FPS (PAL)"));
|
|
|
|
choices.Add(_("29.970 FPS (NTSC)"));
|
2012-03-29 21:04:36 +02:00
|
|
|
if (show_smpte)
|
2009-05-13 22:24:21 +02:00
|
|
|
choices.Add(_("29.970 FPS (NTSC with SMPTE dropframe)"));
|
|
|
|
choices.Add(_("30.000 FPS"));
|
|
|
|
choices.Add(_("50.000 FPS (PAL x2)"));
|
|
|
|
choices.Add(_("59.940 FPS (NTSC x2)"));
|
|
|
|
choices.Add(_("60.000 FPS"));
|
|
|
|
choices.Add(_("119.880 FPS (NTSC x4)"));
|
|
|
|
choices.Add(_("120.000 FPS"));
|
2007-06-18 06:03:58 +02:00
|
|
|
|
2012-03-29 21:04:58 +02:00
|
|
|
wxEndBusyCursor();
|
2011-09-28 21:44:53 +02:00
|
|
|
int choice = wxGetSingleChoiceIndex(_("Please choose the appropriate FPS for the subtitles:"), _("FPS"), choices);
|
2012-03-29 21:04:58 +02:00
|
|
|
wxBeginBusyCursor();
|
|
|
|
|
|
|
|
using agi::vfr::Framerate;
|
2011-12-22 22:27:53 +01:00
|
|
|
if (choice == -1)
|
2012-03-29 21:04:36 +02:00
|
|
|
return Framerate();
|
2007-06-19 07:04:15 +02:00
|
|
|
|
2007-06-18 06:03:58 +02:00
|
|
|
// Get FPS from choice
|
2012-03-29 21:04:36 +02:00
|
|
|
if (vidLoaded)
|
|
|
|
--choice;
|
|
|
|
if (!show_smpte && choice > 4)
|
|
|
|
--choice;
|
2011-12-22 22:27:53 +01:00
|
|
|
|
|
|
|
switch (choice) {
|
2012-03-29 21:04:36 +02:00
|
|
|
case -1: return context->FPS(); break; // VIDEO
|
|
|
|
case 0: return Framerate(15, 1); break;
|
|
|
|
case 1: return Framerate(24000, 1001); break;
|
|
|
|
case 2: return Framerate(24, 1); break;
|
|
|
|
case 3: return Framerate(25, 1); break;
|
|
|
|
case 4: return Framerate(30000, 1001); break;
|
|
|
|
case 5: return Framerate(30000, 1001, true); break;
|
|
|
|
case 6: return Framerate(30, 1); break;
|
|
|
|
case 7: return Framerate(50, 1); break;
|
|
|
|
case 8: return Framerate(60000, 1001); break;
|
|
|
|
case 9: return Framerate(60, 1); break;
|
|
|
|
case 10: return Framerate(120000, 1001); break;
|
|
|
|
case 11: return Framerate(120, 1); break;
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
2011-12-22 22:27:53 +01:00
|
|
|
|
2012-03-29 21:04:36 +02:00
|
|
|
assert(false);
|
|
|
|
return Framerate();
|
2007-06-18 06:03:58 +02:00
|
|
|
}
|
2007-06-19 05:34:53 +02:00
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
void SubtitleFormat::StripTags(AssFile &file) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto current : file.Line | agi::of_type<AssDialogue>())
|
|
|
|
current->StripTags();
|
2011-11-25 20:28:19 +01:00
|
|
|
}
|
2007-06-19 05:34:53 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void SubtitleFormat::ConvertNewlines(AssFile &file, std::string const& newline, bool mergeLineBreaks) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto current : file.Line | agi::of_type<AssDialogue>()) {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string repl = current->Text;
|
|
|
|
boost::replace_all(repl, "\\h", " ");
|
|
|
|
boost::ireplace_all(repl, "\\n", newline);
|
2012-11-05 17:20:58 +01:00
|
|
|
if (mergeLineBreaks) {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string dbl(newline + newline);
|
|
|
|
size_t pos = 0;
|
|
|
|
while ((pos = repl.find(dbl, pos)) != std::string::npos)
|
|
|
|
boost::replace_all(repl, dbl, newline);
|
2007-06-19 05:34:53 +02:00
|
|
|
}
|
2012-12-04 23:35:59 +01:00
|
|
|
current->Text = repl;
|
2007-06-19 05:34:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
void SubtitleFormat::StripComments(AssFile &file) {
|
2012-11-28 17:17:59 +01:00
|
|
|
file.Line.remove_and_dispose_if([](AssEntry const& e) {
|
|
|
|
const AssDialogue *diag = dynamic_cast<const AssDialogue*>(&e);
|
2013-01-04 16:01:50 +01:00
|
|
|
return diag && (diag->Comment || diag->Text.get().empty());
|
2012-11-28 17:17:59 +01:00
|
|
|
}, [](AssEntry *e) { delete e; });
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
void SubtitleFormat::StripNonDialogue(AssFile &file) {
|
2012-11-28 17:17:59 +01:00
|
|
|
file.Line.remove_and_dispose_if([](AssEntry const& e) {
|
2013-06-13 00:54:19 +02:00
|
|
|
return e.Group() != AssEntryGroup::DIALOGUE;
|
2012-11-28 17:17:59 +01:00
|
|
|
}, [](AssEntry *e) { delete e; });
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
static bool dialog_start_lt(AssEntry &pos, AssDialogue *to_insert) {
|
|
|
|
AssDialogue *diag = dynamic_cast<AssDialogue*>(&pos);
|
2011-09-28 21:44:53 +02:00
|
|
|
return diag && diag->Start > to_insert->Start;
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Split and merge lines so there are no overlapping lines
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
///
|
2010-01-06 06:23:58 +01:00
|
|
|
/// Algorithm described at http://devel.aegisub.org/wiki/Technical/SplitMerge
|
2012-10-12 19:16:39 +02:00
|
|
|
void SubtitleFormat::RecombineOverlaps(AssFile &file) {
|
|
|
|
entryIter cur, next = file.Line.begin();
|
2011-09-28 21:44:53 +02:00
|
|
|
cur = next++;
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
for (; next != file.Line.end(); cur = next++) {
|
|
|
|
AssDialogue *prevdlg = dynamic_cast<AssDialogue*>(&*cur);
|
|
|
|
AssDialogue *curdlg = dynamic_cast<AssDialogue*>(&*next);
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
if (!curdlg || !prevdlg) continue;
|
|
|
|
if (prevdlg->End <= curdlg->Start) continue;
|
|
|
|
|
|
|
|
// Use names like in the algorithm description and prepare for erasing
|
|
|
|
// old dialogues from the list
|
2012-10-12 19:16:39 +02:00
|
|
|
entryIter prev = cur;
|
2011-09-28 21:44:53 +02:00
|
|
|
cur = next;
|
|
|
|
next++;
|
|
|
|
|
|
|
|
// std::list::insert() inserts items before the given iterator, so
|
|
|
|
// we need 'next' for inserting. 'prev' and 'cur' can safely be erased
|
|
|
|
// from the list now.
|
2012-10-12 19:16:39 +02:00
|
|
|
file.Line.erase(prev);
|
|
|
|
file.Line.erase(cur);
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
//Is there an A part before the overlap?
|
|
|
|
if (curdlg->Start > prevdlg->Start) {
|
|
|
|
// Produce new entry with correct values
|
2012-11-03 05:06:37 +01:00
|
|
|
AssDialogue *newdlg = new AssDialogue(*prevdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
newdlg->Start = prevdlg->Start;
|
|
|
|
newdlg->End = curdlg->Start;
|
|
|
|
newdlg->Text = prevdlg->Text;
|
|
|
|
|
2012-09-25 03:15:20 +02:00
|
|
|
file.Line.insert(find_if(next, file.Line.end(), std::bind(dialog_start_lt, _1, newdlg)), *newdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Overlapping A+B part
|
|
|
|
{
|
2012-11-03 05:06:37 +01:00
|
|
|
AssDialogue *newdlg = new AssDialogue(*prevdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
newdlg->Start = curdlg->Start;
|
|
|
|
newdlg->End = (prevdlg->End < curdlg->End) ? prevdlg->End : curdlg->End;
|
|
|
|
// Put an ASS format hard linewrap between lines
|
2013-01-04 16:01:50 +01:00
|
|
|
newdlg->Text = curdlg->Text.get() + "\\N" + prevdlg->Text.get();
|
2011-09-28 21:44:53 +02:00
|
|
|
|
2012-09-25 03:15:20 +02:00
|
|
|
file.Line.insert(find_if(next, file.Line.end(), std::bind(dialog_start_lt, _1, newdlg)), *newdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is there an A part after the overlap?
|
|
|
|
if (prevdlg->End > curdlg->End) {
|
|
|
|
// Produce new entry with correct values
|
2012-11-03 05:06:37 +01:00
|
|
|
AssDialogue *newdlg = new AssDialogue(*prevdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
newdlg->Start = curdlg->End;
|
|
|
|
newdlg->End = prevdlg->End;
|
|
|
|
newdlg->Text = prevdlg->Text;
|
|
|
|
|
2012-09-25 03:15:20 +02:00
|
|
|
file.Line.insert(find_if(next, file.Line.end(), std::bind(dialog_start_lt, _1, newdlg)), *newdlg);
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
// Is there a B part after the overlap?
|
|
|
|
if (curdlg->End > prevdlg->End) {
|
|
|
|
// Produce new entry with correct values
|
2012-11-03 05:06:37 +01:00
|
|
|
AssDialogue *newdlg = new AssDialogue(*prevdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
newdlg->Start = prevdlg->End;
|
|
|
|
newdlg->End = curdlg->End;
|
|
|
|
newdlg->Text = curdlg->Text;
|
|
|
|
|
2012-09-25 03:15:20 +02:00
|
|
|
file.Line.insert(find_if(next, file.Line.end(), std::bind(dialog_start_lt, _1, newdlg)), *newdlg);
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
next--;
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
/// @brief Merge identical lines that follow each other
|
2012-10-12 19:16:39 +02:00
|
|
|
void SubtitleFormat::MergeIdentical(AssFile &file) {
|
|
|
|
entryIter cur, next = file.Line.begin();
|
2011-09-28 21:44:53 +02:00
|
|
|
cur = next++;
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
for (; next != file.Line.end(); cur = next++) {
|
|
|
|
AssDialogue *curdlg = dynamic_cast<AssDialogue*>(&*cur);
|
|
|
|
AssDialogue *nextdlg = dynamic_cast<AssDialogue*>(&*next);
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2008-08-11 02:02:36 +02:00
|
|
|
if (curdlg && nextdlg && curdlg->End == nextdlg->Start && curdlg->Text == nextdlg->Text) {
|
2008-07-18 17:39:34 +02:00
|
|
|
// Merge timing
|
2011-09-28 21:44:53 +02:00
|
|
|
nextdlg->Start = std::min(nextdlg->Start, curdlg->Start);
|
|
|
|
nextdlg->End = std::max(nextdlg->End, curdlg->End);
|
2012-03-25 06:05:06 +02:00
|
|
|
|
2008-07-18 17:39:34 +02:00
|
|
|
// Remove duplicate line
|
2012-10-12 19:16:39 +02:00
|
|
|
delete curdlg;
|
2008-07-18 17:39:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-28 21:44:53 +02:00
|
|
|
|
2012-11-28 16:46:33 +01:00
|
|
|
std::vector<SubtitleFormat*> SubtitleFormat::formats;
|
2011-09-28 21:44:53 +02:00
|
|
|
|
|
|
|
void SubtitleFormat::LoadFormats() {
|
|
|
|
if (formats.empty()) {
|
2012-10-12 03:52:36 +02:00
|
|
|
new AssSubtitleFormat;
|
2012-03-29 21:05:26 +02:00
|
|
|
new Ebu3264SubtitleFormat;
|
2012-01-26 21:08:38 +01:00
|
|
|
new EncoreSubtitleFormat;
|
|
|
|
new MKVSubtitleFormat;
|
|
|
|
new MicroDVDSubtitleFormat;
|
|
|
|
new SRTSubtitleFormat;
|
|
|
|
new TTXTSubtitleFormat;
|
|
|
|
new TXTSubtitleFormat;
|
|
|
|
new TranStationSubtitleFormat;
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtitleFormat::DestroyFormats() {
|
2012-11-30 20:47:24 +01:00
|
|
|
while (!formats.empty())
|
|
|
|
delete formats.back();
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template<class Cont, class Pred>
|
2012-10-25 15:45:06 +02:00
|
|
|
SubtitleFormat *find_or_throw(Cont &container, Pred pred) {
|
2012-11-04 04:53:03 +01:00
|
|
|
auto it = find_if(container.begin(), container.end(), pred);
|
2011-09-28 21:44:53 +02:00
|
|
|
if (it == container.end())
|
2012-10-25 15:45:06 +02:00
|
|
|
throw UnknownSubtitleFormatError("Subtitle format for extension not found", 0);
|
2011-09-28 21:44:53 +02:00
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
|
2013-10-05 15:58:15 +02:00
|
|
|
const SubtitleFormat *SubtitleFormat::GetReader(agi::fs::path const& filename, std::string const& encoding) {
|
2011-09-28 21:44:53 +02:00
|
|
|
LoadFormats();
|
2013-10-05 15:58:15 +02:00
|
|
|
return find_or_throw(formats, std::bind(&SubtitleFormat::CanReadFile, _1, filename, encoding));
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
const SubtitleFormat *SubtitleFormat::GetWriter(agi::fs::path const& filename) {
|
2011-09-28 21:44:53 +02:00
|
|
|
LoadFormats();
|
2012-09-25 03:15:20 +02:00
|
|
|
return find_or_throw(formats, std::bind(&SubtitleFormat::CanWriteFile, _1, filename));
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string SubtitleFormat::GetWildcards(int mode) {
|
2011-09-28 21:44:53 +02:00
|
|
|
LoadFormats();
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> all;
|
|
|
|
std::string final;
|
2011-09-28 21:44:53 +02:00
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto format : formats) {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::vector<std::string> cur = mode == 0 ? format->GetReadWildcards() : format->GetWriteWildcards();
|
2011-09-28 21:44:53 +02:00
|
|
|
if (cur.empty()) continue;
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
for_each(cur.begin(), cur.end(), [](std::string &str) { str.insert(0, "*."); });
|
|
|
|
all.insert(all.end(), begin(cur), end(cur));
|
|
|
|
final += "|" + format->GetName() + " (" + boost::join(cur, ",") + ")|" + boost::join(cur, ";");
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
return from_wx(_("All Supported Formats")) + " (" + boost::join(all, ",") + ")|" + boost::join(all, ";") + final;
|
2011-09-28 21:44:53 +02:00
|
|
|
}
|