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

txtsub.cc

00001 /*
00002  * SubTimer source file
00003  *  Copyright (C) 2005 Peter Salvi
00004  *   Last modification: <2005.03.23., 16:20:22>
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 "txtsub.hh"
00026 
00027 TxtSub::TxtSub() : SubTitle()
00028 {
00029   type = TXTSUB;
00030 }
00031 
00032 TxtSub::TxtSub(SubTitle *s) : SubTitle(s)
00033 {
00034   type = TXTSUB;
00035 }
00036 
00037 TxtSub::~TxtSub()
00038 {
00039 }
00040 
00041 bool TxtSub::loadFromFile(QFile *f)
00042 {
00043   QTextStream str(f);
00044   QString s;
00045   int i;
00046 
00047   line_count = 0;
00048   str.setEncoding(QTextStream::UnicodeUTF8);
00049 
00050   while(!str.atEnd()) {   
00051     Event *e = new Event();
00052     s = str.readLine();
00053     if(s.isEmpty())
00054       continue;
00055     i = s.find(':');
00056     e->start = QTime(0, 0);
00057     e->end = QTime(0, 0);
00058     if(i < 0)
00059       e->name = QObject::tr("Default");
00060     else {
00061       e->name = s.left(i).stripWhiteSpace();
00062       s = s.mid(i + 1).stripWhiteSpace();
00063     }
00064     e->dialogue = s.stripWhiteSpace();
00065     events.push_back(e);
00066     ++line_count;
00067   }
00068   return (line_count != 0);
00069 }
00070 
00071 void TxtSub::saveToFile(QFile *f) const
00072 {
00073   QTextStream str(f);
00074   str.setEncoding(QTextStream::UnicodeUTF8);
00075   for(size_t i = 0; i < line_count; ++i)
00076     str << events[i]->name << ": " << events[i]->dialogue << '\n';
00077 }
00078 

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