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 TMPLAYEROUTPUTFORMAT_H 0009 #define TMPLAYEROUTPUTFORMAT_H 0010 0011 #include "formats/outputformat.h" 0012 #include "core/richtext/richdocument.h" 0013 #include "core/subtitleiterator.h" 0014 0015 namespace SubtitleComposer { 0016 class TMPlayerOutputFormat : 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 ret += QString::asprintf(m_timeFormat, showTime.hours(), showTime.minutes(), showTime.seconds()); 0030 0031 QString text = (primary ? line->primaryDoc() : line->secondaryDoc())->toPlainText(); 0032 ret += text.replace('\n', '|'); 0033 ret += '\n'; 0034 0035 // We behave like Subtitle Workshop here: to compensate for the lack of hide time 0036 // indication provisions in the format we add an empty line with the hide time. 0037 Time hideTime = line->hideTime(); 0038 ret += QString::asprintf(m_timeFormat, hideTime.hours(), hideTime.minutes(), hideTime.seconds()); 0039 0040 ret += '\n'; 0041 } 0042 return ret; 0043 } 0044 0045 TMPlayerOutputFormat() : 0046 OutputFormat(QStringLiteral("TMPlayer"), QStringList() << QStringLiteral("sub") << QStringLiteral("txt")), 0047 m_timeFormat("%02d:%02d:%02d:") 0048 {} 0049 0050 TMPlayerOutputFormat(const QString &name, const QStringList &extensions, const char *timeFormat) : 0051 OutputFormat(name, extensions), 0052 m_timeFormat(timeFormat) 0053 {} 0054 0055 const char *m_timeFormat; 0056 }; 0057 0058 class TMPlayerPlusOutputFormat : public TMPlayerOutputFormat 0059 { 0060 friend class FormatManager; 0061 0062 protected: 0063 TMPlayerPlusOutputFormat() : 0064 TMPlayerOutputFormat(QStringLiteral("TMPlayer+"), QStringList() << QStringLiteral("sub") << QStringLiteral("txt"), "%02d:%02d:%02d=") 0065 {} 0066 }; 0067 } 0068 0069 #endif