lib

KoDocumentInfo.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
00003    Copyright (C) 2004 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library 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 GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "KoDocumentInfo.h"
00022 #include "KoDom.h"
00023 #include "KoDocument.h"
00024 #include "kofficeversion.h"
00025 #include "KoApplication.h"
00026 
00027 #include <KoStoreDevice.h>
00028 #include <KoXmlWriter.h>
00029 
00030 #include <kconfig.h>
00031 #include <kdebug.h>
00032 #include <kglobal.h>
00033 #include <klocale.h>
00034 
00035 #include <qobjectlist.h>
00036 #include <qdatetime.h>
00037 #include "KoXmlNS.h"
00038 
00039 /*****************************************
00040  *
00041  * KoDocumentInfo
00042  *
00043  *****************************************/
00044 
00045 KoDocumentInfo::KoDocumentInfo( QObject* parent, const char* name )
00046     : QObject( parent, name )
00047 {
00048     (void)new KoDocumentInfoUserMetadata( this );
00049     (void)new KoDocumentInfoAuthor( this );
00050     (void)new KoDocumentInfoAbout( this );
00051 }
00052 
00053 KoDocumentInfo::~KoDocumentInfo()
00054 {
00055 }
00056 
00057 // KOffice-1.3 format
00058 bool KoDocumentInfo::load( const QDomDocument& doc )
00059 {
00060     QStringList lst = pages();
00061     QStringList::ConstIterator it = lst.begin();
00062     for( ; it != lst.end(); ++it )
00063     {
00064         KoDocumentInfoPage* p = page( *it );
00065         Q_ASSERT( p );
00066         if ( !p->load( doc.documentElement() ) )
00067             return false;
00068     }
00069 
00070     return true;
00071 }
00072 
00073 bool KoDocumentInfo::loadOasis( const QDomDocument& metaDoc )
00074 {
00075     //kdDebug()<<" metaDoc.toString() :"<<metaDoc.toString()<<endl;
00076     QStringList lst = pages();
00077     QStringList::ConstIterator it = lst.begin();
00078     for( ; it != lst.end(); ++it )
00079     {
00080         KoDocumentInfoPage* p = page( *it );
00081         Q_ASSERT( p );
00082 
00083         QDomNode meta   = KoDom::namedItemNS( metaDoc, KoXmlNS::office, "document-meta" );
00084         QDomNode office = KoDom::namedItemNS( meta, KoXmlNS::office, "meta" );
00085 
00086         if ( office.isNull() )
00087             return false;
00088 
00089         if ( !p->loadOasis( office ) )
00090             return false;
00091     }
00092     return true;
00093 }
00094 
00095 // KOffice-1.3 format
00096 QDomDocument KoDocumentInfo::save()
00097 {
00098     QDomDocument doc = KoDocument::createDomDocument( "document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1" );
00099     QDomElement e = doc.documentElement();
00100 
00101     const QStringList lst = pages();
00102     QStringList::ConstIterator it = lst.begin();
00103     for( ; it != lst.end(); ++it )
00104     {
00105         KoDocumentInfoPage* p = page( *it );
00106         Q_ASSERT( p );
00107         QDomElement s = p->save( doc );
00108         if ( s.isNull() )
00109             continue;
00110         e.appendChild( s );
00111     }
00112     if ( e.isNull() )
00113       return QDomDocument();
00114 
00115     return doc;
00116 }
00117 
00118 bool KoDocumentInfo::saveOasis( KoStore* store )
00119 {
00120     KoStoreDevice dev( store );
00121     KoXmlWriter* xmlWriter = KoDocument::createOasisXmlWriter( &dev, "office:document-meta" );
00122     xmlWriter->startElement( "office:meta" );
00123 
00124     xmlWriter->startElement( "meta:generator");
00125     xmlWriter->addTextNode( QString( "KOffice/%1" ).arg( KOFFICE_VERSION_STRING ) );
00126     xmlWriter->endElement();
00127     QStringList lst = pages();
00128     QStringList::ConstIterator it = lst.begin();
00129     for( ; it != lst.end(); ++it )
00130     {
00131         KoDocumentInfoPage* p = page( *it );
00132         Q_ASSERT( p );
00133         if ( !p->saveOasis( *xmlWriter ) )
00134             return false;
00135     }
00136     xmlWriter->endElement();
00137     xmlWriter->endElement(); // root element
00138     xmlWriter->endDocument();
00139     delete xmlWriter;
00140     return true;
00141 }
00142 
00143 KoDocumentInfoPage* KoDocumentInfo::page( const QString& name ) const
00144 {
00145     QObject* obj = const_cast<KoDocumentInfo*>(this)->child( name.latin1() );
00146 
00147     return (KoDocumentInfoPage*)obj;
00148 }
00149 
00150 QStringList KoDocumentInfo::pages() const
00151 {
00152     QStringList ret;
00153 
00154     const QObjectList *list = children();
00155     if ( list )
00156     {
00157         QObjectListIt it( *list );
00158         QObject *obj;
00159         while ( ( obj = it.current() ) )
00160         {
00161             ret.prepend( obj->name() );
00162             ++it;
00163         }
00164     }
00165 
00166     return ret;
00167 }
00168 
00169 QString KoDocumentInfo::title() const
00170 {
00171     KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(page( "about" ));
00172     if ( !aboutPage ) {
00173         kdWarning() << "'About' page not found in documentInfo !" << endl;
00174         return QString::null;
00175     }
00176     else
00177         return aboutPage->title();
00178 }
00179 
00180 QString KoDocumentInfo::creator() const
00181 {
00182     KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(page( "author" ));
00183     if ( !authorPage ) {
00184         kdWarning() << "'Author' page not found in documentInfo !" << endl;
00185         return QString::null;
00186     }
00187     else
00188         return authorPage->fullName();
00189 }
00190 
00191 /*****************************************
00192  *
00193  * KoDocumentInfoPage
00194  *
00195  *****************************************/
00196 
00197 KoDocumentInfoPage::KoDocumentInfoPage( QObject* parent, const char* name )
00198     : QObject( parent, name )
00199 {
00200 }
00201 
00202 /*****************************************
00203  *
00204  * KoDocumentInfoAuthor
00205  *
00206  *****************************************/
00207 
00208 KoDocumentInfoAuthor::KoDocumentInfoAuthor( KoDocumentInfo* info )
00209     : KoDocumentInfoPage( info, "author" )
00210 {
00211     initParameters();
00212 }
00213 
00214 KoDocumentInfoAuthor::~KoDocumentInfoAuthor()
00215 {
00216     delete m_emailCfg;
00217 }
00218 void KoDocumentInfoAuthor::initParameters()
00219 {
00220     KConfig* config = KoGlobal::kofficeConfig();
00221     if ( config->hasGroup( "Author" ) ) {
00222         KConfigGroupSaver cgs( config, "Author" );
00223         m_telephoneHome=config->readEntry( "telephone" );
00224         m_telephoneWork=config->readEntry( "telephone-work" );
00225         m_fax=config->readEntry( "fax" );
00226         m_country=config->readEntry( "country" );
00227         m_postalCode=config->readEntry( "postal-code" );
00228         m_city=config->readEntry( "city" );
00229         m_street=config->readEntry( "street" );
00230     }
00231 
00232   m_emailCfg = new KConfig( "emaildefaults", true );
00233   m_emailCfg->setGroup( "Defaults" );
00234   QString group = m_emailCfg->readEntry("Profile","Default");
00235   m_emailCfg->setGroup(QString("PROFILE_%1").arg(group));
00236 
00237   if ( m_fullName.isNull() ) // only if null. Empty means the user made it explicitly empty.
00238   {
00239     QString name = m_emailCfg->readEntry( "FullName" );
00240     if ( !name.isEmpty() )
00241       m_fullName = name;
00242   }
00243   if ( m_company.isNull() )
00244   {
00245     QString name = m_emailCfg->readEntry( "Organization" );
00246     if ( !name.isEmpty() )
00247       m_company = name;
00248   }
00249 }
00250 
00251 bool KoDocumentInfoAuthor::saveOasis( KoXmlWriter &xmlWriter )
00252 {
00253     if ( !m_fullName.isEmpty() )
00254     {
00255      xmlWriter.startElement( "dc:creator");
00256      xmlWriter.addTextNode( m_fullName );
00257      xmlWriter.endElement();
00258     }
00259     if ( !m_initial.isEmpty() )
00260     {
00261      xmlWriter.startElement( "meta:user-defined");
00262      xmlWriter.addAttribute( "meta:name", "initial" );
00263      xmlWriter.addTextNode( m_initial );
00264      xmlWriter.endElement();
00265     }
00266     if ( !m_title.isEmpty() )
00267     {
00268      xmlWriter.startElement( "meta:user-defined");
00269      xmlWriter.addAttribute( "meta:name", "author-title" );
00270      xmlWriter.addTextNode( m_title );
00271      xmlWriter.endElement();
00272     }
00273     if ( !m_company.isEmpty() )
00274     {
00275      xmlWriter.startElement( "meta:user-defined");
00276      xmlWriter.addAttribute( "meta:name", "company" );
00277      xmlWriter.addTextNode( m_company );
00278      xmlWriter.endElement();
00279     }
00280     if ( !m_email.isEmpty() )
00281     {
00282      xmlWriter.startElement( "meta:user-defined");
00283      xmlWriter.addAttribute( "meta:name", "email" );
00284      xmlWriter.addTextNode( m_email );
00285      xmlWriter.endElement();
00286     }
00287     if ( !m_telephoneHome.isEmpty() )
00288     {
00289      xmlWriter.startElement( "meta:user-defined");
00290      xmlWriter.addAttribute( "meta:name", "telephone" );
00291      xmlWriter.addTextNode( m_telephoneHome );
00292      xmlWriter.endElement();
00293     }
00294     if ( !m_telephoneWork.isEmpty() )
00295     {
00296      xmlWriter.startElement( "meta:user-defined");
00297      xmlWriter.addAttribute( "meta:name", "telephone-work" );
00298      xmlWriter.addTextNode( m_telephoneWork );
00299      xmlWriter.endElement();
00300     }
00301     if ( !m_fax.isEmpty() )
00302     {
00303      xmlWriter.startElement( "meta:user-defined");
00304      xmlWriter.addAttribute( "meta:name", "fax" );
00305      xmlWriter.addTextNode( m_fax );
00306      xmlWriter.endElement();
00307     }
00308     if ( !m_country.isEmpty() )
00309     {
00310      xmlWriter.startElement( "meta:user-defined");
00311      xmlWriter.addAttribute( "meta:name", "country" );
00312      xmlWriter.addTextNode( m_country );
00313      xmlWriter.endElement();
00314     }
00315     if ( !m_postalCode.isEmpty() )
00316     {
00317      xmlWriter.startElement( "meta:user-defined");
00318      xmlWriter.addAttribute( "meta:name", "postal-code" );
00319      xmlWriter.addTextNode( m_postalCode );
00320      xmlWriter.endElement();
00321     }
00322     if ( !m_city.isEmpty() )
00323     {
00324      xmlWriter.startElement( "meta:user-defined");
00325      xmlWriter.addAttribute( "meta:name", "city" );
00326      xmlWriter.addTextNode( m_city );
00327      xmlWriter.endElement();
00328     }
00329     if ( !m_street.isEmpty() )
00330     {
00331      xmlWriter.startElement( "meta:user-defined");
00332      xmlWriter.addAttribute( "meta:name", "street" );
00333      xmlWriter.addTextNode( m_street );
00334      xmlWriter.endElement();
00335     }
00336     if ( !m_position.isEmpty() )
00337     {
00338      xmlWriter.startElement( "meta:user-defined");
00339      xmlWriter.addAttribute( "meta:name", "position" );
00340      xmlWriter.addTextNode( m_position );
00341      xmlWriter.endElement();
00342     }
00343     return true;
00344 }
00345 
00346 bool KoDocumentInfoAuthor::loadOasis( const QDomNode& metaDoc )
00347 {
00348     QDomElement e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "creator" );
00349     if ( !e.isNull() && !e.text().isEmpty() )
00350         m_fullName = e.text();
00351     QDomNode n = metaDoc.firstChild();
00352     for ( ; !n.isNull(); n = n.nextSibling() )
00353     {
00354         if (n.isElement())
00355         {
00356             QDomElement e = n.toElement();
00357             if ( e.namespaceURI() == KoXmlNS::meta && e.localName() == "user-defined" && !e.text().isEmpty() )
00358             {
00359                 QString name = e.attributeNS( KoXmlNS::meta, "name", QString::null );
00360                 if ( name == "initial" )
00361                     m_initial = e.text();
00362                 else if ( name == "author-title" )
00363                     m_title = e.text();
00364                 else if ( name == "company" )
00365                     m_company = e.text();
00366                 else if ( name == "email" )
00367                     m_email = e.text();
00368                 else if ( name == "telephone" )
00369                     m_telephoneHome = e.text();
00370                 else if ( name == "telephone-work" )
00371                     m_telephoneWork = e.text();
00372                 else if ( name == "fax" )
00373                     m_fax = e.text();
00374                 else if ( name == "country" )
00375                     m_country = e.text();
00376                 else if ( name == "postal-code" )
00377                     m_postalCode = e.text();
00378                 else if ( name == "city" )
00379                     m_city = e.text();
00380                 else if ( name == "street" )
00381                     m_street = e.text();
00382                 else if ( name == "position" )
00383                     m_position = e.text();
00384             }
00385         }
00386     }
00387     return true;
00388 }
00389 
00390 // KOffice-1.3 format
00391 bool KoDocumentInfoAuthor::load( const QDomElement& e )
00392 {
00393     QDomNode n = e.namedItem( "author" ).firstChild();
00394     for( ; !n.isNull(); n = n.nextSibling() )
00395     {
00396         QDomElement e = n.toElement();
00397         if ( e.isNull() ) continue;
00398         if ( e.tagName() == "full-name" )
00399             m_fullName = e.text();
00400         else if ( e.tagName() == "initial" )
00401             m_initial = e.text();
00402         else if ( e.tagName() == "title" )
00403             m_title = e.text();
00404         else if ( e.tagName() == "company" )
00405             m_company = e.text();
00406         else if ( e.tagName() == "email" )
00407             m_email = e.text();
00408         else if ( e.tagName() == "telephone" )
00409             m_telephoneHome = e.text();
00410         else if ( e.tagName() == "telephone-work" )
00411             m_telephoneWork = e.text();
00412         else if ( e.tagName() == "fax" )
00413             m_fax = e.text();
00414         else if ( e.tagName() == "country" )
00415             m_country = e.text();
00416         else if ( e.tagName() == "postal-code" )
00417             m_postalCode = e.text();
00418         else if ( e.tagName() == "city" )
00419             m_city = e.text();
00420         else if ( e.tagName() == "street" )
00421             m_street = e.text();
00422         else if ( e.tagName() == "position" )
00423             m_position = e.text();
00424     }
00425     return true;
00426 }
00427 
00428 QDomElement KoDocumentInfoAuthor::save( QDomDocument& doc )
00429 {
00430     QDomElement e = doc.createElement( "author" );
00431 
00432     QDomElement t = doc.createElement( "full-name" );
00433     e.appendChild( t );
00434     t.appendChild( doc.createTextNode( m_fullName ) );
00435 
00436     t = doc.createElement( "initial" );
00437     e.appendChild( t );
00438     t.appendChild( doc.createTextNode( m_initial ) );
00439 
00440 
00441     t = doc.createElement( "title" );
00442     e.appendChild( t );
00443     t.appendChild( doc.createTextNode( m_title ) );
00444 
00445     t = doc.createElement( "company" );
00446     e.appendChild( t );
00447     t.appendChild( doc.createTextNode( m_company ) );
00448 
00449     t = doc.createElement( "email" );
00450     e.appendChild( t );
00451     t.appendChild( doc.createTextNode( m_email ) );
00452 
00453     t = doc.createElement( "telephone" );
00454     e.appendChild( t );
00455     t.appendChild( doc.createTextNode( m_telephoneHome ) );
00456 
00457     t = doc.createElement( "telephone-work" );
00458     e.appendChild( t );
00459     t.appendChild( doc.createTextNode( m_telephoneWork ) );
00460 
00461     t = doc.createElement( "fax" );
00462     e.appendChild( t );
00463     t.appendChild( doc.createTextNode( m_fax ) );
00464 
00465     t = doc.createElement( "country" );
00466     e.appendChild( t );
00467     t.appendChild( doc.createTextNode( m_country ) );
00468 
00469     t = doc.createElement( "postal-code" );
00470     e.appendChild( t );
00471     t.appendChild( doc.createTextNode( m_postalCode ) );
00472 
00473     t = doc.createElement( "city" );
00474     e.appendChild( t );
00475     t.appendChild( doc.createTextNode( m_city ) );
00476 
00477     t = doc.createElement( "street" );
00478     e.appendChild( t );
00479     t.appendChild( doc.createTextNode( m_street ) );
00480 
00481     t = doc.createElement( "position" );
00482     e.appendChild( t );
00483     t.appendChild( doc.createTextNode( m_position ) );
00484 
00485     return e;
00486 }
00487 
00488 QString KoDocumentInfoAuthor::fullName() const
00489 {
00490     return m_fullName;
00491 }
00492 
00493 QString KoDocumentInfoAuthor::initial() const
00494 {
00495     return m_initial;
00496 }
00497 
00498 QString KoDocumentInfoAuthor::title() const
00499 {
00500     return m_title;
00501 }
00502 
00503 QString KoDocumentInfoAuthor::company() const
00504 {
00505     return m_company;
00506 }
00507 
00508 QString KoDocumentInfoAuthor::email() const
00509 {
00510     return m_email;
00511 }
00512 
00513 QString KoDocumentInfoAuthor::telephoneHome() const
00514 {
00515     return m_telephoneHome;
00516 }
00517 
00518 QString KoDocumentInfoAuthor::telephoneWork() const
00519 {
00520     return m_telephoneWork;
00521 }
00522 
00523 QString KoDocumentInfoAuthor::fax() const
00524 {
00525     return m_fax;
00526 }
00527 
00528 QString KoDocumentInfoAuthor::country() const
00529 {
00530     return m_country;
00531 }
00532 
00533 QString KoDocumentInfoAuthor::postalCode() const
00534 {
00535     return m_postalCode;
00536 }
00537 
00538 QString KoDocumentInfoAuthor::city() const
00539 {
00540     return m_city;
00541 }
00542 
00543 QString KoDocumentInfoAuthor::street() const
00544 {
00545     return m_street;
00546 }
00547 
00548 QString KoDocumentInfoAuthor::position() const
00549 {
00550     return m_position;
00551 }
00552 
00553 void KoDocumentInfoAuthor::setFullName( const QString& n )
00554 {
00555     m_fullName = n;
00556 }
00557 
00558 void KoDocumentInfoAuthor::setInitial( const QString& n )
00559 {
00560     m_initial = n;
00561 }
00562 
00563 void KoDocumentInfoAuthor::setTitle( const QString& n )
00564 {
00565     m_title = n;
00566 }
00567 
00568 void KoDocumentInfoAuthor::setCompany( const QString& n )
00569 {
00570     m_company = n;
00571 }
00572 
00573 void KoDocumentInfoAuthor::setEmail( const QString& n )
00574 {
00575     m_email = n;
00576 }
00577 
00578 void KoDocumentInfoAuthor::setTelephoneHome( const QString& n )
00579 {
00580     m_telephoneHome = n;
00581 }
00582 
00583 void KoDocumentInfoAuthor::setTelephoneWork( const QString& n )
00584 {
00585     m_telephoneWork = n;
00586 }
00587 
00588 void KoDocumentInfoAuthor::setFax( const QString& n )
00589 {
00590     m_fax = n;
00591 }
00592 
00593 void KoDocumentInfoAuthor::setCountry( const QString& n )
00594 {
00595     m_country = n;
00596 }
00597 
00598 void KoDocumentInfoAuthor::setPostalCode( const QString& n )
00599 {
00600     m_postalCode = n;
00601 }
00602 
00603 void KoDocumentInfoAuthor::setCity( const QString& n )
00604 {
00605     m_city = n;
00606 }
00607 
00608 void KoDocumentInfoAuthor::setStreet( const QString& n )
00609 {
00610     m_street = n;
00611 }
00612 
00613 void KoDocumentInfoAuthor::setPosition( const QString& n )
00614 {
00615     m_position = n;
00616 }
00617 
00618 
00619 /*****************************************
00620  *
00621  * KoDocumentInfoAbout
00622  *
00623  *****************************************/
00624 
00625 KoDocumentInfoAbout::KoDocumentInfoAbout( KoDocumentInfo* info )
00626     : KoDocumentInfoPage( info, "about" )
00627 {
00628     m_firstSave = true;
00629     m_docInfo = info;
00630     m_editingCycles = 0;
00631     m_initialCreator = m_docInfo->creator();
00632     m_creationDate = QDateTime::currentDateTime();
00633 }
00634 
00635 void KoDocumentInfoAbout::saveParameters()
00636 {
00637     KoDocument* doc = dynamic_cast< KoDocument* >( m_docInfo->parent() );
00638     if ( m_firstSave && doc && !doc->isAutosaving() )
00639        m_editingCycles++;
00640     m_modificationDate = QDateTime::currentDateTime();
00641     m_firstSave = false;
00642 }
00643 
00644 bool KoDocumentInfoAbout::saveOasis( KoXmlWriter &xmlWriter )
00645 {
00646     saveParameters();
00647     if ( !m_title.isEmpty() )
00648     {
00649      xmlWriter.startElement( "dc:title" );
00650      xmlWriter.addTextNode( m_title );
00651      xmlWriter.endElement();
00652     }
00653     if ( !m_abstract.isEmpty() )
00654     {
00655      xmlWriter.startElement( "dc:description" );
00656      xmlWriter.addTextNode( m_abstract );
00657      xmlWriter.endElement();
00658     }
00659     if ( !m_keywords.isEmpty() )
00660     {
00661      xmlWriter.startElement( "meta:keyword" );
00662      xmlWriter.addTextNode( m_keywords );
00663      xmlWriter.endElement();
00664     }
00665     if ( !m_subject.isEmpty() )
00666     {
00667      xmlWriter.startElement( "dc:subject" );
00668      xmlWriter.addTextNode( m_subject );
00669      xmlWriter.endElement();
00670     }
00671     if ( !m_initialCreator.isEmpty() )
00672     {
00673      xmlWriter.startElement( "meta:initial-creator" );
00674      xmlWriter.addTextNode( m_initialCreator );
00675      xmlWriter.endElement();
00676     }
00677 
00678     xmlWriter.startElement( "meta:editing-cycles" );
00679     xmlWriter.addTextNode( QString::number( m_editingCycles ) );
00680     xmlWriter.endElement();
00681 
00682     if ( m_creationDate.isValid() )
00683     {
00684         xmlWriter.startElement( "meta:creation-date" );
00685         xmlWriter.addTextNode( m_creationDate.toString( Qt::ISODate ) );
00686         xmlWriter.endElement();
00687     }
00688 
00689     if ( m_modificationDate.isValid() )
00690     {
00691         xmlWriter.startElement( "dc:date" );
00692         xmlWriter.addTextNode( m_modificationDate.toString( Qt::ISODate ) );
00693         xmlWriter.endElement();
00694     }
00695     return true;
00696 }
00697 
00698 bool KoDocumentInfoAbout::loadOasis( const QDomNode& metaDoc )
00699 {
00700     QDomElement e  = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "title" );
00701     if ( !e.isNull() && !e.text().isEmpty() )
00702     {
00703         m_title = e.text();
00704     }
00705     e  = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "description" );
00706     if ( !e.isNull() && !e.text().isEmpty() )
00707     {
00708         m_abstract = e.text();
00709     }
00710     e  = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "subject" );
00711     if ( !e.isNull() && !e.text().isEmpty() )
00712     {
00713         m_subject = e.text();
00714     }
00715     e  = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "keyword" );
00716     if ( !e.isNull() && !e.text().isEmpty() )
00717     {
00718         m_keywords = e.text();
00719     }
00720     e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "initial-creator" );
00721     if ( !e.isNull() && !e.text().isEmpty() )
00722         m_initialCreator = e.text();
00723     else
00724     m_initialCreator = i18n( "Unknown" );
00725 
00726     e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "editing-cycles" );
00727     if ( !e.isNull() && !e.text().isEmpty() )
00728         m_editingCycles = e.text().toInt();
00729 
00730     e  = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "creation-date" );
00731     if ( !e.isNull() && !e.text().isEmpty() )
00732         m_creationDate = QDateTime::fromString( e.text(), Qt::ISODate );
00733     else
00734         m_creationDate = QDateTime();
00735 
00736     e  = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "date"  );
00737     if ( !e.isNull() && !e.text().isEmpty() )
00738         m_modificationDate = QDateTime::fromString( e.text(), Qt::ISODate );
00739     return true;
00740 }
00741 
00742 // KOffice-1.3 format
00743 bool KoDocumentInfoAbout::load( const QDomElement& e )
00744 {
00745     QDomNode n = e.namedItem( "about" ).firstChild();
00746     for( ; !n.isNull(); n = n.nextSibling()  )
00747     {
00748         QDomElement e = n.toElement();
00749         if ( e.isNull() ) continue;
00750         if ( e.tagName() == "abstract" )
00751             m_abstract = e.text();
00752         else if ( e.tagName() == "title" )
00753             m_title = e.text();
00754         else if ( e.tagName() == "subject" )
00755             m_subject = e.text();
00756         else if ( e.tagName() == "keyword" )
00757             m_keywords = e.text();
00758         else if ( e.tagName() == "initial-creator" )
00759             m_initialCreator = e.text();
00760         else if ( e.tagName() == "editing-cycles" )
00761             m_editingCycles = e.text().toInt();
00762         else if ( e.tagName() == "creation-date" )
00763             m_creationDate = QDateTime::fromString( e.text(), Qt::ISODate );
00764         else if ( e.tagName() == "date" )
00765             m_modificationDate = QDateTime::fromString( e.text(), Qt::ISODate );
00766     }
00767 
00768     return true;
00769 }
00770 
00771 // KOffice-1.3 format
00772 QDomElement KoDocumentInfoAbout::save( QDomDocument& doc )
00773 {
00774     saveParameters();
00775     QDomElement e = doc.createElement( "about" );
00776 
00777     QDomElement t = doc.createElement( "abstract" );
00778     e.appendChild( t );
00779     t.appendChild( doc.createCDATASection( m_abstract ) );
00780 
00781     t = doc.createElement( "title" );
00782     e.appendChild( t );
00783     t.appendChild( doc.createTextNode( m_title ) );
00784 
00785     t = doc.createElement( "keyword" );
00786     e.appendChild( t );
00787     t.appendChild( doc.createTextNode( m_keywords ) );
00788 
00789     t = doc.createElement( "subject" );
00790     e.appendChild( t );
00791     t.appendChild( doc.createTextNode( m_subject ) );
00792 
00793     t = doc.createElement( "initial-creator" );
00794     e.appendChild( t );
00795     t.appendChild( doc.createTextNode( m_initialCreator ) );
00796 
00797     t = doc.createElement( "editing-cycles" );
00798     e.appendChild( t );
00799     t.appendChild( doc.createTextNode( QString::number( m_editingCycles ) ) );
00800 
00801     t = doc.createElement( "creation-date" );
00802     e.appendChild( t );
00803     t.appendChild( doc.createTextNode( m_creationDate.toString( Qt::ISODate ) ) );
00804 
00805     t = doc.createElement( "date" );
00806     e.appendChild( t );
00807     t.appendChild( doc.createTextNode( m_modificationDate.toString( Qt::ISODate ) ) );
00808     return e;
00809 }
00810 
00811 QString KoDocumentInfoAbout::title() const
00812 {
00813     return m_title;
00814 }
00815 
00816 QString KoDocumentInfoAbout::abstract() const
00817 {
00818     return m_abstract;
00819 }
00820 
00821 QString KoDocumentInfoAbout::initialCreator() const
00822 {
00823     return m_initialCreator;
00824 }
00825 
00826 QString KoDocumentInfoAbout::editingCycles() const
00827 {
00828     return QString::number( m_editingCycles );
00829 }
00830 
00831 QString KoDocumentInfoAbout::creationDate() const
00832 {
00833     if ( m_creationDate.isValid() )
00834         return KGlobal::locale()->formatDateTime( m_creationDate );
00835     else
00836         return QString::null;
00837 }
00838 
00839 QString KoDocumentInfoAbout::modificationDate() const
00840 {
00841     if ( m_modificationDate.isValid() )
00842         return KGlobal::locale()->formatDateTime( m_modificationDate );
00843     else
00844         return QString::null;
00845 }
00846 
00847 void KoDocumentInfoAbout::setTitle( const QString& n )
00848 {
00849     m_title = n;
00850 }
00851 
00852 void KoDocumentInfoAbout::setAbstract( const QString& n )
00853 {
00854     m_abstract = n;
00855 }
00856 
00857 QString KoDocumentInfoAbout::keywords() const
00858 {
00859     return m_keywords;
00860 }
00861 
00862 QString KoDocumentInfoAbout::subject() const
00863 {
00864     return m_subject;
00865 }
00866 
00867 void KoDocumentInfoAbout::setKeywords( const QString& n )
00868 {
00869     m_keywords = n;
00870 }
00871 
00872 void KoDocumentInfoAbout::setSubject( const QString& n )
00873 {
00874     m_subject = n;
00875 }
00876 
00877 void KoDocumentInfoAbout::resetMetaData()
00878 {
00879     m_editingCycles = 0;
00880     m_initialCreator = m_docInfo->creator();
00881     m_creationDate = QDateTime::currentDateTime();
00882     m_modificationDate = QDateTime();
00883 }
00884 
00885 /*****************************************
00886  *
00887  * KoDocumentInfoUserMetadata
00888  *
00889  *****************************************/
00890 
00891 KoDocumentInfoUserMetadata::KoDocumentInfoUserMetadata( KoDocumentInfo* info )
00892     : KoDocumentInfoPage( info, "user_metadata" )
00893 {
00894     m_reserved << "initial" << "author-title" << "company" << "email" << "telephone"
00895     << "telephone-work" << "fax" << "country" << "postal-code" << "city" << "street"
00896     << "position";
00897 }
00898 
00899 bool KoDocumentInfoUserMetadata::saveOasis( KoXmlWriter &xmlWriter )
00900 {
00901   QMap<QString, QString>::iterator it;
00902   for ( it = m_metaList.begin(); it != m_metaList.end(); ++it )
00903   {
00904     xmlWriter.startElement( "meta:user-defined");
00905     xmlWriter.addAttribute( "meta:name", it.key() );
00906     xmlWriter.addTextNode( it.data() );
00907     xmlWriter.endElement();
00908   }
00909   return true;
00910 }
00911 
00912 bool KoDocumentInfoUserMetadata::loadOasis( const QDomNode& metaDoc )
00913 {
00914     QDomNode n = metaDoc.firstChild();
00915     for ( ; !n.isNull(); n = n.nextSibling() )
00916     {
00917         if (n.isElement())
00918         {
00919             QDomElement e = n.toElement();
00920             if ( e.namespaceURI() == KoXmlNS::meta && e.localName() == "user-defined" && !e.text().isEmpty() )
00921             {
00922                 QString name = e.attributeNS( KoXmlNS::meta, "name", QString::null );
00923                 if ( !m_reserved.contains( name ) )
00924                     m_metaList[ name ] = e.text();
00925             }
00926         }
00927     }
00928     return true;
00929 }
00930 
00931 // KOffice-1.3 format
00932 bool KoDocumentInfoUserMetadata::load( const QDomElement& )
00933 {
00934     return true;
00935 }
00936 
00937 // KOffice-1.3 format
00938 QDomElement KoDocumentInfoUserMetadata::save( QDomDocument& )
00939 {
00940     return QDomElement();
00941 }
00942 
00943 #include <KoDocumentInfo.moc>
KDE Home | KDE Accessibility Home | Description of Access Keys