File indexing completed on 2024-12-22 04:40:08

0001 /*
0002     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
0003     SPDX-FileCopyrightText: 2010-2022 Mladen Milinkovic <max@smoothware.net>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef SUBRIPOUTPUTFORMAT_H
0009 #define SUBRIPOUTPUTFORMAT_H
0010 
0011 #include "formats/outputformat.h"
0012 #include "core/richtext/richdocument.h"
0013 #include "core/subtitleiterator.h"
0014 
0015 namespace SubtitleComposer {
0016 class SubRipOutputFormat : public OutputFormat
0017 {
0018     friend class FormatManager;
0019 
0020 protected:
0021     QString dumpSubtitles(const Subtitle &subtitle, bool primary) const override
0022     {
0023         QString ret;
0024 
0025         for(SubtitleIterator it(subtitle); it.current(); ++it) {
0026             const SubtitleLine *line = it.current();
0027 
0028             Time showTime = line->showTime();
0029             Time hideTime = line->hideTime();
0030             ret += QString::asprintf("%d\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\n", it.index() + 1, showTime.hours(), showTime.minutes(), showTime.seconds(), showTime.millis(), hideTime.hours(), hideTime.minutes(), hideTime.seconds(), hideTime.millis());
0031 
0032             const RichString text = (primary ? line->primaryDoc() : line->secondaryDoc())->toRichText();
0033 
0034             ret += text.richString().replace(QLatin1String("&amp;"), QLatin1String("&")).replace(QLatin1String("&lt;"), QLatin1String("<")).replace(QLatin1String("&gt;"), QLatin1String(">"));
0035 
0036             ret += QStringLiteral("\n\n");
0037         }
0038         return ret;
0039     }
0040 
0041     SubRipOutputFormat() :
0042         OutputFormat(QStringLiteral("SubRip"), QStringList(QStringLiteral("srt"))),
0043         m_dialogueBuilder(QStringLiteral("%1%2%3%4%5%6%7\n\n"))
0044     {}
0045 
0046     const QString m_dialogueBuilder;
0047 };
0048 }
0049 
0050 #endif