Rev 454 | Rev 456 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
364 | Franz | 1 | #include "txtim.h" |
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 | |||
9 | QString FileFormatName() |
||
10 | { |
||
11 | return QObject::tr("Text Files"); |
||
12 | } |
||
13 | |||
14 | QStringList FileExtensions() |
||
15 | { |
||
16 | return QStringList("txt"); |
||
17 | } |
||
18 | |||
19 | void GetText(QString filename, QString encoding, bool textOnly, gtWriter *writer) |
||
20 | { |
||
21 | TxtIm* tim = new TxtIm(filename, encoding, writer); |
||
22 | tim->write(); |
||
23 | delete tim; |
||
24 | } |
||
25 | |||
26 | TxtIm::TxtIm(const QString& fname, const QString& enc, gtWriter *w) |
||
27 | { |
||
28 | filename = fname; |
||
29 | encoding = enc; |
||
30 | writer = w; |
||
31 | loadText(); |
||
32 | toUnicode(); |
||
33 | } |
||
34 | |||
35 | void TxtIm::write() |
||
36 | { |
||
37 | writer->append(text); |
||
38 | } |
||
39 | |||
40 | void TxtIm::loadText() |
||
41 | { |
||
42 | text = ""; |
||
43 | QFile f(filename); |
||
44 | QFileInfo fi(f); |
||
45 | if (!fi.exists()) |
||
46 | return; |
||
47 | uint posi; |
||
48 | QByteArray bb(f.size()); |
||
49 | if (f.open(IO_ReadOnly)) |
||
50 | { |
||
51 | f.readBlock(bb.data(), f.size()); |
||
52 | f.close(); |
||
53 | for (posi = 0; posi < bb.size(); ++posi) |
||
54 | text += bb[posi]; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | void TxtIm::toUnicode() |
||
59 | { |
||
60 | QTextCodec *codec; |
||
61 | if (encoding == "") |
||
62 | codec = QTextCodec::codecForLocale(); |
||
63 | else |
||
64 | codec = QTextCodec::codecForName(encoding); |
||
65 | QString dec = codec->toUnicode( text ); |
||
66 | text = dec; |
||
67 | } |
||
68 | |||
69 | TxtIm::~TxtIm() |
||
70 | { |
||
71 | |||
72 | } |