1 /*
2     SPDX-FileCopyrightText: 2007-2009 Sergio Pistone <sergio_pistone@yahoo.com.ar>
3     SPDX-FileCopyrightText: 2010-2019 Mladen Milinkovic <max@smoothware.net>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef SUBRIPOUTPUTFORMAT_H
9 #define SUBRIPOUTPUTFORMAT_H
10 
11 #include "formats/outputformat.h"
12 #include "core/richdocument.h"
13 #include "core/subtitleiterator.h"
14 
15 namespace SubtitleComposer {
16 class SubRipOutputFormat : public OutputFormat
17 {
18 	friend class FormatManager;
19 
20 protected:
dumpSubtitles(const Subtitle & subtitle,bool primary)21 	QString dumpSubtitles(const Subtitle &subtitle, bool primary) const override
22 	{
23 		QString ret;
24 
25 		for(SubtitleIterator it(subtitle); it.current(); ++it) {
26 			const SubtitleLine *line = it.current();
27 
28 			Time showTime = line->showTime();
29 			Time hideTime = line->hideTime();
30 			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());
31 
32 			const SString text = (primary ? line->primaryDoc() : line->secondaryDoc())->toRichText();
33 
34 			ret += text.richString().replace(QLatin1String("&amp;"), QLatin1String("&")).replace(QLatin1String("&lt;"), QLatin1String("<")).replace(QLatin1String("&gt;"), QLatin1String(">"));
35 
36 			ret += QStringLiteral("\n\n");
37 		}
38 		return ret;
39 	}
40 
SubRipOutputFormat()41 	SubRipOutputFormat() :
42 		OutputFormat(QStringLiteral("SubRip"), QStringList(QStringLiteral("srt"))),
43 		m_dialogueBuilder(QStringLiteral("%1%2%3%4%5%6%7\n\n"))
44 	{}
45 
46 	const QString m_dialogueBuilder;
47 };
48 }
49 
50 #endif
51