Főoldal | Osztályhierarchia | Osztálylista | Fájllista | Osztálytagok | Fájlelemek | Kapcsolódó lapok

ssasub.cc

00001 /*
00002  * SubTimer source file
00003  *  Copyright (C) 2005 Peter Salvi
00004  *   Last modification: <2005.03.23., 16:18:34>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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" << // todo
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 }

Projekt: SubTimer Készült: Wed Mar 23 22:06:53 2005 Készítette: doxygen 1.3.6