Rev 12 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | paul | 1 | /*************************************************************************** |
2 | serializer.cpp - description |
||
3 | ------------------- |
||
4 | begin : Sat May 5 2001 |
||
5 | copyright : (C) 2001 by Franz Schmid |
||
6 | email : Franz.Schmid@altmuehlnet.de |
||
7 | ***************************************************************************/ |
||
8 | |||
9 | /*************************************************************************** |
||
10 | * * |
||
11 | * This program is free software; you can redistribute it and/or modify * |
||
12 | * it under the terms of the GNU General Public License as published by * |
||
13 | * the Free Software Foundation; either version 2 of the License, or * |
||
14 | * (at your option) any later version. * |
||
15 | * * |
||
16 | ***************************************************************************/ |
||
17 | |||
18 | #include "serializer.h" |
||
19 | #include <qfile.h> |
||
20 | #include <qtextstream.h> |
||
21 | #include <qtextcodec.h> |
||
22 | extern bool loadText(QString nam, QString *Buffer); |
||
23 | Serializer::Serializer(QString name) |
||
24 | { |
||
25 | Filename = name; |
||
26 | Objekt = ""; |
||
27 | } |
||
28 | |||
29 | QString Serializer::GetObjekt() |
||
30 | { |
||
31 | return Objekt; |
||
32 | } |
||
33 | |||
34 | void Serializer::PutText(PageItem *Item) |
||
35 | { |
||
36 | uint a; |
||
37 | bool Uni = false; |
||
38 | QString Dat = ""; |
||
39 | QPtrList<Pti> y = Item->Ptext; |
||
40 | for (a=0; a<y.count(); ++a) |
||
41 | { |
||
42 | QString b = y.at(a)->ch; |
||
43 | if (b == QChar(13)) |
||
44 | b = "\n"; |
||
45 | if (b[0].unicode() > 255) |
||
46 | Uni = true; |
||
47 | Dat += b; |
||
48 | } |
||
49 | if (Uni) |
||
50 | Objekt = Dat.utf8(); |
||
51 | else |
||
52 | Objekt = Dat; |
||
53 | } |
||
54 | |||
55 | void Serializer::GetText(PageItem *Item, int Absatz, bool Append) |
||
56 | { |
||
57 | struct Pti *hg; |
||
58 | PageItem *nb; |
||
59 | uint a; |
||
60 | if (!Append) |
||
61 | { |
||
62 | if (Item->NextBox != 0) |
||
63 | { |
||
64 | nb = Item->NextBox; |
||
65 | while (nb != 0) |
||
66 | { |
||
67 | nb->Ptext.clear(); |
||
68 | nb->CPos = 0; |
||
69 | nb->Dirty = true; |
||
70 | nb = nb->NextBox; |
||
71 | } |
||
72 | } |
||
73 | Item->Ptext.clear(); |
||
74 | Item->CPos = 0; |
||
75 | } |
||
76 | for (a=0; a<Objekt.length(); ++a) |
||
77 | { |
||
78 | hg = new Pti; |
||
79 | hg->ch = Objekt.at(a); |
||
80 | if (hg->ch == QChar(10)) { hg->ch = QChar(13); } |
||
81 | if (hg->ch == QChar(5)) { hg->ch = QChar(13); } |
||
82 | if (hg->ch == QChar(9)) { hg->ch = " "; } |
||
83 | hg->cfont = Item->IFont; |
||
84 | hg->csize = Item->ISize; |
||
85 | hg->ccolor = Item->Pcolor2; |
||
86 | hg->cextra = 0; |
||
87 | hg->cshade = Item->Shade2; |
||
88 | hg->cselect = false; |
||
89 | hg->cstyle = 0; |
||
90 | hg->cab = Absatz; |
||
91 | hg->xp = 0; |
||
92 | hg->yp = 0; |
||
93 | hg->PRot = 0; |
||
94 | hg->PtransX = 0; |
||
95 | hg->PtransY = 0; |
||
96 | if (Append) |
||
97 | Item->Ptext.insert(Item->CPos, hg); |
||
98 | else |
||
99 | Item->Ptext.append(hg); |
||
100 | Item->CPos += 1; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | bool Serializer::Write() |
||
105 | { |
||
106 | QFile f(Filename); |
||
107 | bool ret = false; |
||
108 | if (f.open(IO_WriteOnly)) |
||
109 | { |
||
110 | QTextStream t(&f); |
||
111 | t.writeRawBytes(Objekt, Objekt.length()); |
||
112 | f.close(); |
||
113 | ret = true; |
||
114 | } |
||
115 | else |
||
116 | { |
||
117 | ret = false; |
||
118 | } |
||
119 | return ret; |
||
120 | } |
||
121 | |||
122 | bool Serializer::Read() |
||
123 | { |
||
124 | bool tmp = loadText(Filename, &Objekt); |
||
125 | QTextCodec* codec = QTextCodec::codecForContent(Objekt, Objekt.length()); |
||
126 | if (codec) |
||
127 | { |
||
128 | if (QString(codec->name()) == "UTF-8") |
||
129 | { |
||
130 | QString dec = QString::fromUtf8(Objekt); |
||
131 | Objekt = dec; |
||
132 | } |
||
133 | } |
||
134 | return tmp; |
||
135 | } |