MythTV  master
srtwriter.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 #ifndef SRTWRITER_H_
3 #define SRTWRITER_H_
4 
5 #include <QStringList>
6 #include <QImage>
7 #include <QPoint>
8 #include <QHash>
9 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
10 #include <QStringConverter>
11 #endif
12 #include <QTime>
13 
14 #include <QtXml/QDomDocument>
15 #include <QtXml/QDomElement>
16 
17 #include "avformatdecoder.h"
18 #include "mythplayer.h"
20 #include "format.h"
21 
22 #include "mythccextractorplayer.h"
23 
24 class OneSubtitle;
25 
31 {
32  public:
33  explicit SRTWriter(const QString &fileName) :
34  m_outFile(fileName), m_outStream(&m_outFile)
35  {
36 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
37  m_outStream.setCodec("UTF-8");
38 #else
39  m_outStream.setEncoding(QStringConverter::Utf8);
40 #endif
41  if (!m_outFile.open(QFile::WriteOnly))
42  {
43  LOG(VB_GENERAL, LOG_ERR, QString("Failed to create '%1'")
44  .arg(fileName));
45  }
46  else
47  {
48  LOG(VB_GENERAL, LOG_DEBUG, QString("Created '%1'")
49  .arg(fileName));
50  }
51  }
52  ~SRTWriter(void)
53  {
54  m_outFile.close();
55  }
56 
57  void AddSubtitle(const OneSubtitle &sub, int number);
58 
59  bool IsOpen(void) { return m_outFile.isOpen(); }
60  void Flush(void) { m_outStream.flush(); }
61 
62  private:
64  static QString FormatTime(std::chrono::milliseconds time_in_msec);
66  QFile m_outFile;
68  QTextStream m_outStream;
69 };
70 
71 #endif /* SRTWRITER_H_ */
SRTWriter::IsOpen
bool IsOpen(void)
Definition: srtwriter.h:59
format.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythplayer.h
OneSubtitle
Represents one subtitle record.
Definition: mythccextractorplayer.h:29
teletextextractorreader.h
SRTWriter::SRTWriter
SRTWriter(const QString &fileName)
Definition: srtwriter.h:33
SRTWriter
Class to write SubRip files.
Definition: srtwriter.h:30
SRTWriter::m_outStream
QTextStream m_outStream
Output stream associated with m_outFile.
Definition: srtwriter.h:68
SRTWriter::m_outFile
QFile m_outFile
Output file.
Definition: srtwriter.h:66
mythccextractorplayer.h
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
avformatdecoder.h
SRTWriter::Flush
void Flush(void)
Definition: srtwriter.h:60
SRTWriter::~SRTWriter
~SRTWriter(void)
Definition: srtwriter.h:52