Subversion Repositories Scribus

Rev

Rev 456 | Rev 2877 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
838 cbradney 1
#include <qobject.h>
364 Franz 2
#include <qcstring.h>
3
#include <qfile.h>
4
#include <qfileinfo.h>
5
#include <qstring.h>
6
#include <qstringlist.h>
7
#include <qtextcodec.h> 
8
 
838 cbradney 9
#include "txtim.h"
10
 
364 Franz 11
QString FileFormatName()
12
{
13
    return QObject::tr("Text Files");
14
}
15
 
16
QStringList FileExtensions()
17
{
18
    return QStringList("txt");
19
}
20
 
21
void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
22
{
456 fschmid 23
        TxtIm* tim = new TxtIm(filename, encoding, textOnly, writer);
364 Franz 24
        tim->write();
25
        delete tim;
26
}
27
 
456 fschmid 28
TxtIm::TxtIm(const QString& fname, const QString& enc, bool textO, gtWriter *w)
364 Franz 29
{
30
        filename = fname;
31
        encoding = enc;
32
        writer = w;
456 fschmid 33
        textOnly = textO;
364 Franz 34
        loadText();
35
        toUnicode();
36
}
37
 
38
void TxtIm::write()
39
{
40
        writer->append(text);
41
}
42
 
43
void TxtIm::loadText()
44
{
45
        text = "";
46
        QFile f(filename);
47
        QFileInfo fi(f);
48
        if (!fi.exists())
49
                return;
50
        uint posi;
51
        QByteArray bb(f.size());
52
        if (f.open(IO_ReadOnly))
53
        {
54
                f.readBlock(bb.data(), f.size());
55
                f.close();
56
                for (posi = 0; posi < bb.size(); ++posi)
57
                        text += bb[posi];
58
        }
59
}
60
 
61
void TxtIm::toUnicode()
62
{
63
        QTextCodec *codec;
64
        if (encoding == "")
65
                codec = QTextCodec::codecForLocale();
66
        else
67
                codec = QTextCodec::codecForName(encoding);
68
        QString dec = codec->toUnicode( text );
69
        text = dec;
70
}
71
 
72
TxtIm::~TxtIm()
73
{
74
 
75
}