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