Subversion Repositories Scribus

Rev

Rev 5093 | 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"
11381 jghali 17
#include "util.h"
838 cbradney 18
 
364 Franz 19
QString FileFormatName()
20
{
21
    return QObject::tr("Text Files");
22
}
23
 
24
QStringList FileExtensions()
25
{
26
    return QStringList("txt");
27
}
28
 
29
void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer)
30
{
456 fschmid 31
        TxtIm* tim = new TxtIm(filename, encoding, textOnly, writer);
364 Franz 32
        tim->write();
33
        delete tim;
34
}
35
 
456 fschmid 36
TxtIm::TxtIm(const QString& fname, const QString& enc, bool textO, gtWriter *w)
364 Franz 37
{
38
        filename = fname;
39
        encoding = enc;
40
        writer = w;
456 fschmid 41
        textOnly = textO;
364 Franz 42
        loadText();
43
}
44
 
45
void TxtIm::write()
46
{
47
        writer->append(text);
48
}
49
 
50
void TxtIm::loadText()
51
{
11381 jghali 52
        QCString rawText;
53
        if (loadRawText(filename, rawText))
54
                text = toUnicode(rawText);
364 Franz 55
}
56
 
11381 jghali 57
QString TxtIm::toUnicode(const QCString& rawText)
364 Franz 58
{
59
        QTextCodec *codec;
2877 cbradney 60
        if (encoding.isEmpty())
364 Franz 61
                codec = QTextCodec::codecForLocale();
62
        else
63
                codec = QTextCodec::codecForName(encoding);
11381 jghali 64
        QString unistr = codec->toUnicode( rawText );
65
        return unistr;
364 Franz 66
}
67
 
68
TxtIm::~TxtIm()
69
{
70
 
71
}