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

srtsub.cc

00001 /*
00002  * SubTimer source file
00003  *  Copyright (C) 2005 Peter Salvi
00004  *   Last modification: <2005.03.23., 16:18:12>
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 <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 }

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