filters

kword13document.cpp

00001 /*
00002    This file is part of the KDE project
00003    Copyright (C) 2004 Nicolas GOUTTE <goutte@kde.org>
00004 
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qiodevice.h>
00022 
00023 #include <kdebug.h>
00024 #include <ktempfile.h>
00025 
00026 #include "kword13utils.h"
00027 #include "kword13layout.h"
00028 #include "kword13picture.h"
00029 #include "kword13document.h"
00030 
00031 KWord13Document::KWord13Document( void ) : m_previewFile( 0 )
00032 {
00033     m_normalTextFramesetList.setAutoDelete( true );
00034     m_tableFramesetList.setAutoDelete( true );
00035     m_otherFramesetList.setAutoDelete( true );
00036     m_headerFooterFramesetList.setAutoDelete( true );
00037     m_footEndNoteFramesetList.setAutoDelete( true );
00038     m_pictureFramesetList.setAutoDelete( true );
00039     m_pictureDict.setAutoDelete( true );
00040 }
00041 
00042 KWord13Document::~KWord13Document( void )
00043 {
00044     delete m_previewFile;
00045 }
00046 
00047 void KWord13Document::xmldump( QIODevice* io )
00048 {
00049     QTextStream iostream( io );
00050     iostream.setEncoding( QTextStream::UnicodeUTF8 );
00051     
00052     iostream << "<?xml encoding='UTF-8'?>\n";
00053     iostream << "<kworddocument>\n";
00054     
00055     for ( QMap<QString,QString>::ConstIterator it = m_documentProperties.begin();
00056         it != m_documentProperties.end();
00057         ++it)
00058     {
00059         iostream << " <param key=\"" << it.key() << "\" data=\"" << EscapeXmlDump( it.data() ) << "\"/>\n";
00060     }
00061     
00062     iostream << " <documentinfo>\n";
00063     for ( QMap<QString,QString>::ConstIterator it11 = m_documentInfo.begin();
00064         it11 != m_documentInfo.end();
00065         ++it11)
00066     {
00067         iostream << "  <param key=\"" << it11.key() << "\" data=\"" << EscapeXmlDump( it11.data() ) << "\"/>\n";
00068     }
00069     iostream << " </documentinfo>\n";
00070     
00071     iostream << " <normalframesets>\n";
00072     for ( KWordTextFrameset* item = m_normalTextFramesetList.first();
00073         item;
00074         item = m_normalTextFramesetList.next() )
00075     {
00076         item->xmldump( iostream );
00077     }
00078     iostream << " </normalframesets>\n";
00079     
00080     iostream << " <tableframesets>\n";
00081     for ( KWordTextFrameset* item12 = m_tableFramesetList.first();
00082         item12;
00083         item12 = m_tableFramesetList.next() )
00084     {
00085         item12->xmldump( iostream );
00086     }
00087     iostream << " </tableframesets>\n";
00088     
00089     iostream << " <headerfooterframesets>\n";
00090     for ( KWordTextFrameset* item2 = m_headerFooterFramesetList.first();
00091         item2;
00092         item2 = m_headerFooterFramesetList.next() )
00093     {
00094         item2->xmldump( iostream );
00095     }
00096     iostream << " </headerfooterframesets>\n";
00097     
00098     iostream << " <footendnoteframesets>\n";
00099     for ( KWordTextFrameset* item3 = m_footEndNoteFramesetList.first();
00100         item3;
00101         item3 = m_footEndNoteFramesetList.next() )
00102     {
00103         item3->xmldump( iostream );
00104     }
00105     iostream << " </footendnoteframesets>\n";
00106     
00107     iostream << " <otherframesets>\n";
00108     for ( KWord13Frameset* item4 = m_otherFramesetList.first();
00109         item4;
00110         item4 = m_otherFramesetList.next() )
00111     {
00112         item4->xmldump( iostream );
00113     }
00114     iostream << " </otherframesets>\n";
00115     
00116     iostream << " <pictureframesets>\n";
00117     for ( KWord13Frameset* item5 = m_pictureFramesetList.first();
00118         item5;
00119         item5 = m_pictureFramesetList.next() )
00120     {
00121         item5->xmldump( iostream );
00122     }
00123     iostream << " </pictureframesets>\n";
00124     
00125     iostream << " <styles>\n";
00126     
00127     for ( QValueList<KWord13Layout>::Iterator it2 = m_styles.begin();
00128         it2 != m_styles.end();
00129         ++it2)
00130     {
00131         (*it2).xmldump( iostream );
00132     }
00133     
00134     iostream << " </styles>\n";
00135     
00136     iostream << " <pictures>\n";
00137     
00138     for ( QDictIterator<KWord13Picture> it3( m_pictureDict ) ; it3.current(); ++it3 )
00139     {
00140         iostream << "  <key>" << it3.currentKey() << "</key>" << endl;
00141     }
00142     
00143     iostream << " </pictures>\n";
00144     
00145     iostream << "</kworddocument>\n";
00146 }
00147 
00148 QString KWord13Document::getDocumentInfo( const QString& name ) const
00149 {
00150     QMap<QString,QString>::ConstIterator it ( m_documentInfo.find( name ) );
00151     if ( it == m_documentInfo.end() )
00152     {
00153         // Property does not exist
00154         return QString::null;
00155     }
00156     else
00157     {
00158         return it.data();
00159     }
00160 }
00161 
00162 QString KWord13Document::getProperty( const QString& name, const QString& oldName ) const
00163 {
00164     const QString result ( getPropertyInternal( name ) );
00165     
00166     if ( result.isEmpty() && !oldName.isEmpty() )
00167     {
00168         // The result is empty result and we have an old name, so try the old name
00169         return getPropertyInternal( oldName );
00170     }
00171     else
00172     {
00173         return result;
00174     }
00175 }
00176 
00177 QString KWord13Document::getPropertyInternal( const QString& name ) const
00178 {
00179     QMap<QString,QString>::ConstIterator it ( m_documentProperties.find( name ) );
00180     if ( it == m_documentProperties.end() )
00181     {
00182         // Property does not exist
00183         return QString::null;
00184     }
00185     else
00186     {
00187         return it.data();
00188     }
00189 }
00190 
00191 QDateTime KWord13Document::lastPrintingDate( void ) const
00192 {
00193     const QString strDate( getPropertyInternal( "VARIABLESETTINGS:lastPrintingDate" ) );
00194     
00195     QDateTime dt;
00196     
00197     if ( strDate.isEmpty() )
00198     {
00199         // The printing date only exists in syntax 3, so we have no fallback.
00200         kdDebug(30520) << "No syntax 3 printing date!" << endl;
00201     }
00202     else
00203     {
00204         dt = QDateTime::fromString( strDate, Qt::ISODate );
00205     }
00206     return dt;
00207 }
00208 
00209 QDateTime KWord13Document::creationDate( void ) const
00210 {
00211     const QString strDate( getPropertyInternal( "VARIABLESETTINGS:creationDate" ) );
00212     
00213     QDateTime dt;
00214     
00215     if ( strDate.isEmpty() )
00216     {
00217         kdDebug(30520) << "No syntax 3 creation date!" << endl;
00218         const int year = getPropertyInternal( "VARIABLESETTINGS:createFileYear" ).toInt();
00219         const int month = getPropertyInternal( "VARIABLESETTINGS:createFileMonth" ).toInt();
00220         const int day = getPropertyInternal( "VARIABLESETTINGS:createFileDay" ).toInt();
00221         
00222         if ( QDate::isValid( year, month, day) )
00223         {
00224             dt.setDate( QDate ( year, month, day) );
00225         }
00226         else
00227         {
00228             kdDebug(30520) << "No syntax 2 creation date!" << endl;
00229         }
00230     }
00231     else
00232     {
00233         dt = QDateTime::fromString( strDate, Qt::ISODate );
00234     }
00235     return dt;
00236 }
00237 
00238 QDateTime KWord13Document::modificationDate( void ) const
00239 {
00240     const QString strDate( getPropertyInternal( "VARIABLESETTINGS:modificationDate" ) );
00241     
00242     QDateTime dt;
00243     
00244     if ( strDate.isEmpty() )
00245     {
00246         kdDebug(30520) << "No syntax 3 modification date!" << endl;
00247         const int year = getPropertyInternal( "VARIABLESETTINGS:modifyFileYear" ).toInt();
00248         const int month = getPropertyInternal( "VARIABLESETTINGS:modifyFileMonth" ).toInt();
00249         const int day = getPropertyInternal( "VARIABLESETTINGS:modifyFileDay" ).toInt();
00250         if ( QDate::isValid( year, month, day) )
00251         {
00252             dt.setDate( QDate ( year, month, day) );
00253         }
00254         else
00255         {
00256             kdDebug(30520) << "No syntax 2 modification date!" << endl;
00257         }
00258     }
00259     else
00260     {
00261         dt = QDateTime::fromString( strDate, Qt::ISODate );
00262     }
00263     return dt;
00264 }
KDE Home | KDE Accessibility Home | Description of Access Keys