Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
838 cbradney 7
#include <qobject.h>
364 Franz 8
#include <qcstring.h>
9
#include <qfile.h>
10
#include <qfileinfo.h>
11
#include <qstring.h>
12
#include <qstringlist.h>
13
#include <qtextcodec.h> 
14
 
838 cbradney 15
#include "txtim.h"
2986 craig 16
#include "scribusstructs.h"
838 cbradney 17
 
364 Franz 18
QString FileFormatName()
19
{
20
    return QObject::tr("Text Files");
21
}
22
 
23
QStringList FileExtensions()
24
{
25
    return QStringList("txt");
26
}
27
 
28
void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
29
{
456 fschmid 30
        TxtIm* tim = new TxtIm(filename, encoding, textOnly, writer);
364 Franz 31
        tim->write();
32
        delete tim;
33
}
34
 
456 fschmid 35
TxtIm::TxtIm(const QString& fname, const QString& enc, bool textO, gtWriter *w)
364 Franz 36
{
37
        filename = fname;
38
        encoding = enc;
39
        writer = w;
456 fschmid 40
        textOnly = textO;
364 Franz 41
        loadText();
42
        toUnicode();
43
}
44
 
45
void TxtIm::write()
46
{
47
        writer->append(text);
48
}
49
 
50
void TxtIm::loadText()
51
{
52
        text = "";
53
        QFile f(filename);
54
        QFileInfo fi(f);
55
        if (!fi.exists())
56
                return;
57
        uint posi;
58
        QByteArray bb(f.size());
59
        if (f.open(IO_ReadOnly))
60
        {
61
                f.readBlock(bb.data(), f.size());
62
                f.close();
63
                for (posi = 0; posi < bb.size(); ++posi)
3041 fschmid 64
                        text += QChar(bb[posi]);
364 Franz 65
        }
66
}
67
 
68
void TxtIm::toUnicode()
69
{
70
        QTextCodec *codec;
2877 cbradney 71
        if (encoding.isEmpty())
364 Franz 72
                codec = QTextCodec::codecForLocale();
73
        else
74
                codec = QTextCodec::codecForName(encoding);
75
        QString dec = codec->toUnicode( text );
76
        text = dec;
77
}
78
 
79
TxtIm::~TxtIm()
80
{
81
 
82
}