summaryrefslogtreecommitdiffstats
path: root/filters/kword/kword1.3/import/kword13document.cpp
blob: af9899d468bf4d44883c2bb35e4b067f87f4f283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
   This file is part of the KDE project
   Copyright (C) 2004 Nicolas GOUTTE <goutte@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 2
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <tqiodevice.h>

#include <kdebug.h>
#include <tdetempfile.h>

#include "kword13utils.h"
#include "kword13layout.h"
#include "kword13picture.h"
#include "kword13document.h"

KWord13Document::KWord13Document( void ) : m_previewFile( 0 )
{
    m_normalTextFramesetList.setAutoDelete( true );
    m_tableFramesetList.setAutoDelete( true );
    m_otherFramesetList.setAutoDelete( true );
    m_headerFooterFramesetList.setAutoDelete( true );
    m_footEndNoteFramesetList.setAutoDelete( true );
    m_pictureFramesetList.setAutoDelete( true );
    m_pictureDict.setAutoDelete( true );
}

KWord13Document::~KWord13Document( void )
{
    delete m_previewFile;
}

void KWord13Document::xmldump( TQIODevice* io )
{
    TQTextStream iostream( io );
    iostream.setEncoding( TQTextStream::UnicodeUTF8 );
    
    iostream << "<?xml encoding='UTF-8'?>\n";
    iostream << "<kworddocument>\n";
    
    for ( TQMap<TQString,TQString>::ConstIterator it = m_documentProperties.begin();
        it != m_documentProperties.end();
        ++it)
    {
        iostream << " <param key=\"" << it.key() << "\" data=\"" << EscapeXmlDump( it.data() ) << "\"/>\n";
    }
    
    iostream << " <documentinfo>\n";
    for ( TQMap<TQString,TQString>::ConstIterator it11 = m_documentInfo.begin();
        it11 != m_documentInfo.end();
        ++it11)
    {
        iostream << "  <param key=\"" << it11.key() << "\" data=\"" << EscapeXmlDump( it11.data() ) << "\"/>\n";
    }
    iostream << " </documentinfo>\n";
    
    iostream << " <normalframesets>\n";
    for ( KWordTextFrameset* item = m_normalTextFramesetList.first();
        item;
        item = m_normalTextFramesetList.next() )
    {
        item->xmldump( iostream );
    }
    iostream << " </normalframesets>\n";
    
    iostream << " <tableframesets>\n";
    for ( KWordTextFrameset* item12 = m_tableFramesetList.first();
        item12;
        item12 = m_tableFramesetList.next() )
    {
        item12->xmldump( iostream );
    }
    iostream << " </tableframesets>\n";
    
    iostream << " <headerfooterframesets>\n";
    for ( KWordTextFrameset* item2 = m_headerFooterFramesetList.first();
        item2;
        item2 = m_headerFooterFramesetList.next() )
    {
        item2->xmldump( iostream );
    }
    iostream << " </headerfooterframesets>\n";
    
    iostream << " <footendnoteframesets>\n";
    for ( KWordTextFrameset* item3 = m_footEndNoteFramesetList.first();
        item3;
        item3 = m_footEndNoteFramesetList.next() )
    {
        item3->xmldump( iostream );
    }
    iostream << " </footendnoteframesets>\n";
    
    iostream << " <otherframesets>\n";
    for ( KWord13Frameset* item4 = m_otherFramesetList.first();
        item4;
        item4 = m_otherFramesetList.next() )
    {
        item4->xmldump( iostream );
    }
    iostream << " </otherframesets>\n";
    
    iostream << " <pictureframesets>\n";
    for ( KWord13Frameset* item5 = m_pictureFramesetList.first();
        item5;
        item5 = m_pictureFramesetList.next() )
    {
        item5->xmldump( iostream );
    }
    iostream << " </pictureframesets>\n";
    
    iostream << " <styles>\n";
    
    for ( TQValueList<KWord13Layout>::Iterator it2 = m_styles.begin();
        it2 != m_styles.end();
        ++it2)
    {
        (*it2).xmldump( iostream );
    }
    
    iostream << " </styles>\n";
    
    iostream << " <pictures>\n";
    
    for ( TQDictIterator<KWord13Picture> it3( m_pictureDict ) ; it3.current(); ++it3 )
    {
        iostream << "  <key>" << it3.currentKey() << "</key>" << endl;
    }
    
    iostream << " </pictures>\n";
    
    iostream << "</kworddocument>\n";
}

TQString KWord13Document::getDocumentInfo( const TQString& name ) const
{
    TQMap<TQString,TQString>::ConstIterator it ( m_documentInfo.find( name ) );
    if ( it == m_documentInfo.end() )
    {
        // Property does not exist
        return TQString();
    }
    else
    {
        return it.data();
    }
}

TQString KWord13Document::getProperty( const TQString& name, const TQString& oldName ) const
{
    const TQString result ( getPropertyInternal( name ) );
    
    if ( result.isEmpty() && !oldName.isEmpty() )
    {
        // The result is empty result and we have an old name, so try the old name
        return getPropertyInternal( oldName );
    }
    else
    {
        return result;
    }
}

TQString KWord13Document::getPropertyInternal( const TQString& name ) const
{
    TQMap<TQString,TQString>::ConstIterator it ( m_documentProperties.find( name ) );
    if ( it == m_documentProperties.end() )
    {
        // Property does not exist
        return TQString();
    }
    else
    {
        return it.data();
    }
}

TQDateTime KWord13Document::lastPrintingDate( void ) const
{
    const TQString strDate( getPropertyInternal( "VARIABLESETTINGS:lastPrintingDate" ) );
    
    TQDateTime dt;
    
    if ( strDate.isEmpty() )
    {
        // The printing date only exists in syntax 3, so we have no fallback.
        kdDebug(30520) << "No syntax 3 printing date!" << endl;
    }
    else
    {
        dt = TQDateTime::fromString( strDate, TQt::ISODate );
    }
    return dt;
}

TQDateTime KWord13Document::creationDate( void ) const
{
    const TQString strDate( getPropertyInternal( "VARIABLESETTINGS:creationDate" ) );
    
    TQDateTime dt;
    
    if ( strDate.isEmpty() )
    {
        kdDebug(30520) << "No syntax 3 creation date!" << endl;
        const int year = getPropertyInternal( "VARIABLESETTINGS:createFileYear" ).toInt();
        const int month = getPropertyInternal( "VARIABLESETTINGS:createFileMonth" ).toInt();
        const int day = getPropertyInternal( "VARIABLESETTINGS:createFileDay" ).toInt();
        
        if ( TQDate::isValid( year, month, day) )
        {
            dt.setDate( TQDate ( year, month, day) );
        }
        else
        {
            kdDebug(30520) << "No syntax 2 creation date!" << endl;
        }
    }
    else
    {
        dt = TQDateTime::fromString( strDate, TQt::ISODate );
    }
    return dt;
}

TQDateTime KWord13Document::modificationDate( void ) const
{
    const TQString strDate( getPropertyInternal( "VARIABLESETTINGS:modificationDate" ) );
    
    TQDateTime dt;
    
    if ( strDate.isEmpty() )
    {
        kdDebug(30520) << "No syntax 3 modification date!" << endl;
        const int year = getPropertyInternal( "VARIABLESETTINGS:modifyFileYear" ).toInt();
        const int month = getPropertyInternal( "VARIABLESETTINGS:modifyFileMonth" ).toInt();
        const int day = getPropertyInternal( "VARIABLESETTINGS:modifyFileDay" ).toInt();
        if ( TQDate::isValid( year, month, day) )
        {
            dt.setDate( TQDate ( year, month, day) );
        }
        else
        {
            kdDebug(30520) << "No syntax 2 modification date!" << endl;
        }
    }
    else
    {
        dt = TQDateTime::fromString( strDate, TQt::ISODate );
    }
    return dt;
}