00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qfile.h>
00022 #include <qtextstream.h>
00023
00024 #include "ssasub.hh"
00025
00026 SsaSub::SsaSub() : SubTitle()
00027 {
00028 type = SSASUB;
00029 }
00030
00031 SsaSub::SsaSub(SubTitle *s) : SubTitle(s)
00032 {
00033 type = SSASUB;
00034 }
00035
00036 SsaSub::~SsaSub()
00037 {
00038 }
00039
00040 bool SsaSub::loadFromFile(QFile *f)
00041 {
00042 QTextStream str(f);
00043 QString s;
00044 bool ok = true;
00045
00046 line_count = 0;
00047 str.setEncoding(QTextStream::UnicodeUTF8);
00048
00049 while(!str.atEnd()) {
00050 Event *e = new Event();
00051 s = str.readLine();
00052 if(s.find("Dialogue:") != 0)
00053 continue;
00054
00055 if(!extractTime(s.section(',', 1, 1), e->start)) {
00056 ok = false;
00057 break;
00058 }
00059 if(!extractTime(s.section(',', 2, 2), e->end)) {
00060 ok = false;
00061 break;
00062 }
00063 e->name = s.section(',', 4, 4);
00064 e->dialogue = s.section(',', 9);
00065 if(s.endsWith(","))
00066 e->dialogue = e->dialogue.append(",");
00067
00068 events.push_back(e);
00069 ++line_count;
00070 }
00071 return ok & (line_count != 0);
00072 }
00073
00074 void SsaSub::saveToFile(QFile *f) const
00075 {
00076 QTextStream str(f);
00077 str.setEncoding(QTextStream::UnicodeUTF8);
00078 str << "[Script Info]\n" <<
00079 "; This is a Sub Station Alpha v4 script.\n" <<
00080 "; This was generated by SubTimer at " <<
00081 QDateTime::currentDateTime().toString() << "\n\n" <<
00082 "[V4 Styles]\n" <<
00083 "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, " <<
00084 "TertiaryColour, BackColour, Bold, Italic, BorderStyle, Outline, " <<
00085 "Shadow, Alignment, MarginL, MarginR, MarginV, AlphaLevel, Encoding\n" <<
00086 "\n\n" <<
00087 "[Events]\n" <<
00088 "Format: Marked, Start, End, Style, Name, MarginL, MarginR, " <<
00089 "MarginV, Effect, Text\n";
00090 for(size_t i = 0; i < line_count; ++i)
00091 str << "Dialogue: Marked=0," <<
00092 events[i]->start.toString("hh:mm:ss.zzz").mid(1, 10) <<
00093 "," << events[i]->end.toString("hh:mm:ss.zzz").mid(1, 10) << "," <<
00094 "*Default," << events[i]->name << ",0000,0000,0000,," <<
00095 events[i]->dialogue << '\n';
00096 }