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 <qobject.h>
00023 #include <qtextstream.h>
00024
00025 #include "srtsub.hh"
00026
00027 SrtSub::SrtSub() : SubTitle()
00028 {
00029 type = SRTSUB;
00030 }
00031
00032 SrtSub::SrtSub(SubTitle *s) : SubTitle(s)
00033 {
00034 type = SRTSUB;
00035 }
00036
00037 SrtSub::~SrtSub()
00038 {
00039 }
00040
00041 bool SrtSub::loadFromFile(QFile *f)
00042 {
00043 QTextStream str(f);
00044 bool ok = true;
00045 QString s, s1;
00046 int i;
00047
00048 line_count = 0;
00049 str.setEncoding(QTextStream::UnicodeUTF8);
00050
00051 while(!str.atEnd()) {
00052 do {
00053 s = str.readLine();
00054 } while((i = s.find("-->")) < 0 && !str.atEnd());
00055
00056 if(!str.atEnd()) {
00057 Event *e = new Event();
00058 if(!extractTime(s.left(i - 1), e->start, true)) {
00059 ok = false;
00060 break;
00061 }
00062 if(!extractTime(s.mid(i + 4), e->end, true)) {
00063 ok = false;
00064 break;
00065 }
00066 s = str.readLine().stripWhiteSpace();
00067 s1 = str.readLine().stripWhiteSpace();
00068 while(!s1.isEmpty() && !str.atEnd()) {
00069 if(!s.isEmpty())
00070 s = s.append("\\N").append(s1);
00071 else
00072 s = s1;
00073 s1 = str.readLine().stripWhiteSpace();
00074 }
00075 e->name = QObject::tr("Default");
00076 e->dialogue = s;
00077 events.push_back(e);
00078 ++line_count;
00079 }
00080 }
00081 return ok & (line_count != 0);
00082 }
00083
00084 void SrtSub::saveToFile(QFile *f) const
00085 {
00086 QTextStream str(f);
00087 str.setEncoding(QTextStream::UnicodeUTF8);
00088 for(size_t i = 0; i < line_count; ++i) {
00089 str << i+1 << '\n';
00090 str << events[i]->start.toString("hh:mm:ss,zzz") <<
00091 " --> " << events[i]->end.toString("hh:mm:ss,zzz") << '\n';
00092 str << events[i]->dialogue.replace("\\N", "\n", FALSE) << "\n\n";
00093 }
00094 }