koDocumentInfo.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00033 #include <qobjectlist.h>
00034 #include "koxmlns.h"
00035
00036
00037
00038
00039
00040
00041
00042 KoDocumentInfo::KoDocumentInfo( QObject* parent, const char* name )
00043 : QObject( parent, name )
00044 {
00045 (void)new KoDocumentInfoAuthor( this );
00046 (void)new KoDocumentInfoAbout( this );
00047 }
00048
00049 KoDocumentInfo::~KoDocumentInfo()
00050 {
00051 }
00052
00053
00054 bool KoDocumentInfo::load( const QDomDocument& doc )
00055 {
00056 QStringList lst = pages();
00057 QStringList::ConstIterator it = lst.begin();
00058 for( ; it != lst.end(); ++it )
00059 {
00060 KoDocumentInfoPage* p = page( *it );
00061 Q_ASSERT( p );
00062 if ( !p->load( doc.documentElement() ) )
00063 return false;
00064 }
00065
00066 return true;
00067 }
00068
00069 bool KoDocumentInfo::loadOasis( const QDomDocument& metaDoc )
00070 {
00071
00072 QStringList lst = pages();
00073 QStringList::ConstIterator it = lst.begin();
00074 for( ; it != lst.end(); ++it )
00075 {
00076 KoDocumentInfoPage* p = page( *it );
00077 Q_ASSERT( p );
00078
00079 QDomNode meta = KoDom::namedItemNS( metaDoc, KoXmlNS::office, "document-meta" );
00080 QDomNode office = KoDom::namedItemNS( meta, KoXmlNS::office, "meta" );
00081
00082 if ( office.isNull() )
00083 return false;
00084
00085 if ( !p->loadOasis( office ) )
00086 return false;
00087 }
00088 return true;
00089 }
00090
00091
00092 QDomDocument KoDocumentInfo::save()
00093 {
00094 QDomDocument doc = KoDocument::createDomDocument( "document-info" , "document-info" , "1.1" );
00095 QDomElement e = doc.documentElement();
00096
00097 QStringList lst = pages();
00098 QStringList::ConstIterator it = lst.begin();
00099 for( ; it != lst.end(); ++it )
00100 {
00101 KoDocumentInfoPage* p = page( *it );
00102 Q_ASSERT( p );
00103 QDomElement s = p->save( doc );
00104 if ( s.isNull() )
00105 return QDomDocument();
00106 e.appendChild( s );
00107 }
00108
00109 return doc;
00110 }
00111
00112 bool KoDocumentInfo::saveOasis( KoStore* store )
00113 {
00114 KoStoreDevice dev( store );
00115 KoXmlWriter* xmlWriter = KoDocument::createOasisXmlWriter( &dev, "office:document-meta" );
00116 xmlWriter->startElement( "office:meta" );
00117
00118 xmlWriter->startElement( "meta:generator");
00119 xmlWriter->addTextNode( QString( "KOffice/%1" ).arg( KOFFICE_VERSION_STRING ) );
00120 xmlWriter->endElement();
00121 QStringList lst = pages();
00122 QStringList::ConstIterator it = lst.begin();
00123 for( ; it != lst.end(); ++it )
00124 {
00125 KoDocumentInfoPage* p = page( *it );
00126 Q_ASSERT( p );
00127 if ( !p->saveOasis( *xmlWriter ) )
00128 return false;
00129 }
00130 xmlWriter->endElement();
00131 xmlWriter->endElement();
00132 xmlWriter->endDocument();
00133 delete xmlWriter;
00134 return true;
00135 }
00136
00137 KoDocumentInfoPage* KoDocumentInfo::page( const QString& name ) const
00138 {
00139 QObject* obj = const_cast<KoDocumentInfo*>(this)->child( name.latin1() );
00140
00141 return (KoDocumentInfoPage*)obj;
00142 }
00143
00144 QStringList KoDocumentInfo::pages() const
00145 {
00146 QStringList ret;
00147
00148 const QObjectList *list = children();
00149 if ( list )
00150 {
00151 QObjectListIt it( *list );
00152 QObject *obj;
00153 while ( ( obj = it.current() ) )
00154 {
00155 ret.append( obj->name() );
00156 ++it;
00157 }
00158 }
00159
00160 return ret;
00161 }
00162
00163 QString KoDocumentInfo::title() const
00164 {
00165 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(page( "about" ));
00166 if ( !aboutPage ) {
00167 kdWarning() << "'About' page not found in documentInfo !" << endl;
00168 return QString::null;
00169 }
00170 else
00171 return aboutPage->title();
00172 }
00173
00174
00175
00176
00177
00178
00179
00180 KoDocumentInfoPage::KoDocumentInfoPage( QObject* parent, const char* name )
00181 : QObject( parent, name )
00182 {
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 KoDocumentInfoAuthor::KoDocumentInfoAuthor( KoDocumentInfo* info )
00192 : KoDocumentInfoPage( info, "author" )
00193 {
00194 initParameters();
00195 }
00196
00197 KoDocumentInfoAuthor::~KoDocumentInfoAuthor()
00198 {
00199 delete m_emailCfg;
00200 }
00201 void KoDocumentInfoAuthor::initParameters()
00202 {
00203 KConfig* config = KoGlobal::kofficeConfig();
00204 if ( config->hasGroup( "Author" ) ) {
00205 KConfigGroupSaver cgs( config, "Author" );
00206 m_telephoneHome=config->readEntry( "telephone" );
00207 m_telephoneWork=config->readEntry( "telephone-work" );
00208 m_fax=config->readEntry( "fax" );
00209 m_country=config->readEntry( "country" );
00210 m_postalCode=config->readEntry( "postal-code" );
00211 m_city=config->readEntry( "city" );
00212 m_street=config->readEntry( "street" );
00213 }
00214
00215 m_emailCfg = new KConfig( "emaildefaults", true );
00216 m_emailCfg->setGroup( "Defaults" );
00217 QString group = m_emailCfg->readEntry("Profile","Default");
00218 m_emailCfg->setGroup(QString("PROFILE_%1").arg(group));
00219
00220 if ( m_fullName.isNull() )
00221 {
00222 QString name = m_emailCfg->readEntry( "FullName" );
00223 if ( !name.isEmpty() )
00224 m_fullName = name;
00225 }
00226 if ( m_company.isNull() )
00227 {
00228 QString name = m_emailCfg->readEntry( "Organization" );
00229 if ( !name.isEmpty() )
00230 m_company = name;
00231 }
00232 if ( m_email.isNull() )
00233 {
00234 QString email = m_emailCfg->readEntry( "EmailAddress" );
00235 if ( !email.isEmpty() )
00236 m_email = email;
00237 }
00238
00239 }
00240
00241 bool KoDocumentInfoAuthor::saveOasis( KoXmlWriter &xmlWriter )
00242 {
00243 if ( !m_fullName.isEmpty() )
00244 {
00245 xmlWriter.startElement( "dc:creator");
00246 xmlWriter.addTextNode( m_fullName );
00247 xmlWriter.endElement();
00248 }
00249 if ( !m_initial.isEmpty() )
00250 {
00251 xmlWriter.startElement( "meta:user-defined");
00252 xmlWriter.addAttribute( "meta:name", "initial" );
00253 xmlWriter.addTextNode( m_initial );
00254 xmlWriter.endElement();
00255 }
00256 if ( !m_title.isEmpty() )
00257 {
00258 xmlWriter.startElement( "meta:user-defined");
00259 xmlWriter.addAttribute( "meta:name", "author-title" );
00260 xmlWriter.addTextNode( m_title );
00261 xmlWriter.endElement();
00262 }
00263 if ( !m_company.isEmpty() )
00264 {
00265 xmlWriter.startElement( "meta:user-defined");
00266 xmlWriter.addAttribute( "meta:name", "company" );
00267 xmlWriter.addTextNode( m_company );
00268 xmlWriter.endElement();
00269 }
00270 if ( !m_email.isEmpty() )
00271 {
00272 xmlWriter.startElement( "meta:user-defined");
00273 xmlWriter.addAttribute( "meta:name", "email" );
00274 xmlWriter.addTextNode( m_email );
00275 xmlWriter.endElement();
00276 }
00277 if ( !m_telephoneHome.isEmpty() )
00278 {
00279 xmlWriter.startElement( "meta:user-defined");
00280 xmlWriter.addAttribute( "meta:name", "telephone" );
00281 xmlWriter.addTextNode( m_telephoneHome );
00282 xmlWriter.endElement();
00283 }
00284 if ( !m_telephoneWork.isEmpty() )
00285 {
00286 xmlWriter.startElement( "meta:user-defined");
00287 xmlWriter.addAttribute( "meta:name", "telephone-work" );
00288 xmlWriter.addTextNode( m_telephoneWork );
00289 xmlWriter.endElement();
00290 }
00291 if ( !m_fax.isEmpty() )
00292 {
00293 xmlWriter.startElement( "meta:user-defined");
00294 xmlWriter.addAttribute( "meta:name", "fax" );
00295 xmlWriter.addTextNode( m_fax );
00296 xmlWriter.endElement();
00297 }
00298 if ( !m_country.isEmpty() )
00299 {
00300 xmlWriter.startElement( "meta:user-defined");
00301 xmlWriter.addAttribute( "meta:name", "country" );
00302 xmlWriter.addTextNode( m_country );
00303 xmlWriter.endElement();
00304 }
00305 if ( !m_postalCode.isEmpty() )
00306 {
00307 xmlWriter.startElement( "meta:user-defined");
00308 xmlWriter.addAttribute( "meta:name", "postal-code" );
00309 xmlWriter.addTextNode( m_postalCode );
00310 xmlWriter.endElement();
00311 }
00312 if ( !m_city.isEmpty() )
00313 {
00314 xmlWriter.startElement( "meta:user-defined");
00315 xmlWriter.addAttribute( "meta:name", "city" );
00316 xmlWriter.addTextNode( m_city );
00317 xmlWriter.endElement();
00318 }
00319 if ( !m_street.isEmpty() )
00320 {
00321 xmlWriter.startElement( "meta:user-defined");
00322 xmlWriter.addAttribute( "meta:name", "street" );
00323 xmlWriter.addTextNode( m_street );
00324 xmlWriter.endElement();
00325 }
00326 if ( !m_position.isEmpty() )
00327 {
00328 xmlWriter.startElement( "meta:user-defined");
00329 xmlWriter.addAttribute( "meta:name", "position" );
00330 xmlWriter.addTextNode( m_position );
00331 xmlWriter.endElement();
00332 }
00333 return true;
00334 }
00335
00336 bool KoDocumentInfoAuthor::loadOasis( const QDomNode& metaDoc )
00337 {
00338 QDomElement e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "creator" );
00339 if ( !e.isNull() && !e.text().isEmpty() )
00340 m_fullName = e.text();
00341 QDomNode n = metaDoc.firstChild();
00342 for ( ; !n.isNull(); n = n.nextSibling() )
00343 {
00344 if (n.isElement())
00345 {
00346 QDomElement e = n.toElement();
00347 if ( e.namespaceURI() == KoXmlNS::meta && e.localName() == "user-defined" && !e.text().isEmpty() )
00348 {
00349 QString name = e.attributeNS( KoXmlNS::meta, "name", QString::null );
00350 if ( name == "initial" )
00351 m_initial = e.text();
00352 else if ( name == "author-title" )
00353 m_title = e.text();
00354 else if ( name == "company" )
00355 m_company = e.text();
00356 else if ( name == "email" )
00357 m_email = e.text();
00358 else if ( name == "telephone" )
00359 m_telephoneHome = e.text();
00360 else if ( name == "telephone-work" )
00361 m_telephoneWork = e.text();
00362 else if ( name == "fax" )
00363 m_fax = e.text();
00364 else if ( name == "country" )
00365 m_country = e.text();
00366 else if ( name == "postal-code" )
00367 m_postalCode = e.text();
00368 else if ( name == "city" )
00369 m_city = e.text();
00370 else if ( name == "street" )
00371 m_street = e.text();
00372 else if ( name == "position" )
00373 m_position = e.text();
00374 }
00375 }
00376 }
00377 return true;
00378 }
00379
00380
00381 bool KoDocumentInfoAuthor::load( const QDomElement& e )
00382 {
00383 QDomNode n = e.namedItem( "author" ).firstChild();
00384 for( ; !n.isNull(); n = n.nextSibling() )
00385 {
00386 QDomElement e = n.toElement();
00387 if ( e.isNull() ) continue;
00388 if ( e.tagName() == "full-name" )
00389 m_fullName = e.text();
00390 else if ( e.tagName() == "initial" )
00391 m_initial = e.text();
00392 else if ( e.tagName() == "title" )
00393 m_title = e.text();
00394 else if ( e.tagName() == "company" )
00395 m_company = e.text();
00396 else if ( e.tagName() == "email" )
00397 m_email = e.text();
00398 else if ( e.tagName() == "telephone" )
00399 m_telephoneHome = e.text();
00400 else if ( e.tagName() == "telephone-work" )
00401 m_telephoneWork = e.text();
00402 else if ( e.tagName() == "fax" )
00403 m_fax = e.text();
00404 else if ( e.tagName() == "country" )
00405 m_country = e.text();
00406 else if ( e.tagName() == "postal-code" )
00407 m_postalCode = e.text();
00408 else if ( e.tagName() == "city" )
00409 m_city = e.text();
00410 else if ( e.tagName() == "street" )
00411 m_street = e.text();
00412 else if ( e.tagName() == "position" )
00413 m_position = e.text();
00414 }
00415 return true;
00416 }
00417
00418 QDomElement KoDocumentInfoAuthor::save( QDomDocument& doc )
00419 {
00420 QDomElement e = doc.createElement( "author" );
00421
00422 QDomElement t = doc.createElement( "full-name" );
00423 e.appendChild( t );
00424 t.appendChild( doc.createTextNode( m_fullName ) );
00425
00426 t = doc.createElement( "initial" );
00427 e.appendChild( t );
00428 t.appendChild( doc.createTextNode( m_initial ) );
00429
00430
00431 t = doc.createElement( "title" );
00432 e.appendChild( t );
00433 t.appendChild( doc.createTextNode( m_title ) );
00434
00435 t = doc.createElement( "company" );
00436 e.appendChild( t );
00437 t.appendChild( doc.createTextNode( m_company ) );
00438
00439 t = doc.createElement( "email" );
00440 e.appendChild( t );
00441 t.appendChild( doc.createTextNode( m_email ) );
00442
00443 t = doc.createElement( "telephone" );
00444 e.appendChild( t );
00445 t.appendChild( doc.createTextNode( m_telephoneHome ) );
00446
00447 t = doc.createElement( "telephone-work" );
00448 e.appendChild( t );
00449 t.appendChild( doc.createTextNode( m_telephoneWork ) );
00450
00451 t = doc.createElement( "fax" );
00452 e.appendChild( t );
00453 t.appendChild( doc.createTextNode( m_fax ) );
00454
00455 t = doc.createElement( "country" );
00456 e.appendChild( t );
00457 t.appendChild( doc.createTextNode( m_country ) );
00458
00459 t = doc.createElement( "postal-code" );
00460 e.appendChild( t );
00461 t.appendChild( doc.createTextNode( m_postalCode ) );
00462
00463 t = doc.createElement( "city" );
00464 e.appendChild( t );
00465 t.appendChild( doc.createTextNode( m_city ) );
00466
00467 t = doc.createElement( "street" );
00468 e.appendChild( t );
00469 t.appendChild( doc.createTextNode( m_street ) );
00470
00471 t = doc.createElement( "position" );
00472 e.appendChild( t );
00473 t.appendChild( doc.createTextNode( m_position ) );
00474
00475 return e;
00476 }
00477
00478 QString KoDocumentInfoAuthor::fullName() const
00479 {
00480 return m_fullName;
00481 }
00482
00483 QString KoDocumentInfoAuthor::initial() const
00484 {
00485 return m_initial;
00486 }
00487
00488 QString KoDocumentInfoAuthor::title() const
00489 {
00490 return m_title;
00491 }
00492
00493 QString KoDocumentInfoAuthor::company() const
00494 {
00495 return m_company;
00496 }
00497
00498 QString KoDocumentInfoAuthor::email() const
00499 {
00500 return m_email;
00501 }
00502
00503 QString KoDocumentInfoAuthor::telephoneHome() const
00504 {
00505 return m_telephoneHome;
00506 }
00507
00508 QString KoDocumentInfoAuthor::telephoneWork() const
00509 {
00510 return m_telephoneWork;
00511 }
00512
00513 QString KoDocumentInfoAuthor::fax() const
00514 {
00515 return m_fax;
00516 }
00517
00518 QString KoDocumentInfoAuthor::country() const
00519 {
00520 return m_country;
00521 }
00522
00523 QString KoDocumentInfoAuthor::postalCode() const
00524 {
00525 return m_postalCode;
00526 }
00527
00528 QString KoDocumentInfoAuthor::city() const
00529 {
00530 return m_city;
00531 }
00532
00533 QString KoDocumentInfoAuthor::street() const
00534 {
00535 return m_street;
00536 }
00537
00538 QString KoDocumentInfoAuthor::position() const
00539 {
00540 return m_position;
00541 }
00542
00543 void KoDocumentInfoAuthor::setFullName( const QString& n )
00544 {
00545 m_fullName = n;
00546 }
00547
00548 void KoDocumentInfoAuthor::setInitial( const QString& n )
00549 {
00550 m_initial = n;
00551 }
00552
00553 void KoDocumentInfoAuthor::setTitle( const QString& n )
00554 {
00555 m_title = n;
00556 }
00557
00558 void KoDocumentInfoAuthor::setCompany( const QString& n )
00559 {
00560 m_company = n;
00561 }
00562
00563 void KoDocumentInfoAuthor::setEmail( const QString& n )
00564 {
00565 m_email = n;
00566 }
00567
00568 void KoDocumentInfoAuthor::setTelephoneHome( const QString& n )
00569 {
00570 m_telephoneHome = n;
00571 }
00572
00573 void KoDocumentInfoAuthor::setTelephoneWork( const QString& n )
00574 {
00575 m_telephoneWork = n;
00576 }
00577
00578 void KoDocumentInfoAuthor::setFax( const QString& n )
00579 {
00580 m_fax = n;
00581 }
00582
00583 void KoDocumentInfoAuthor::setCountry( const QString& n )
00584 {
00585 m_country = n;
00586 }
00587
00588 void KoDocumentInfoAuthor::setPostalCode( const QString& n )
00589 {
00590 m_postalCode = n;
00591 }
00592
00593 void KoDocumentInfoAuthor::setCity( const QString& n )
00594 {
00595 m_city = n;
00596 }
00597
00598 void KoDocumentInfoAuthor::setStreet( const QString& n )
00599 {
00600 m_street = n;
00601 }
00602
00603 void KoDocumentInfoAuthor::setPosition( const QString& n )
00604 {
00605 m_position = n;
00606 }
00607
00608
00609
00610
00611
00612
00613
00614
00615 KoDocumentInfoAbout::KoDocumentInfoAbout( KoDocumentInfo* info )
00616 : KoDocumentInfoPage( info, "about" )
00617 {
00618 }
00619
00620 bool KoDocumentInfoAbout::saveOasis( KoXmlWriter &xmlWriter )
00621 {
00622 if ( !m_title.isEmpty() )
00623 {
00624 xmlWriter.startElement( "dc:title");
00625 xmlWriter.addTextNode( m_title );
00626 xmlWriter.endElement();
00627 }
00628 if ( !m_abstract.isEmpty() )
00629 {
00630 xmlWriter.startElement( "dc:description");
00631 xmlWriter.addTextNode( m_abstract );
00632 xmlWriter.endElement();
00633 }
00634 if ( !m_keywords.isEmpty() )
00635 {
00636 xmlWriter.startElement( "meta:keyword");
00637 xmlWriter.addTextNode( m_keywords );
00638 xmlWriter.endElement();
00639 }
00640 if ( !m_subject.isEmpty() )
00641 {
00642 xmlWriter.startElement( "dc:subject");
00643 xmlWriter.addTextNode( m_subject );
00644 xmlWriter.endElement();
00645 }
00646
00647 return true;
00648 }
00649
00650 bool KoDocumentInfoAbout::loadOasis( const QDomNode& metaDoc )
00651 {
00652 QDomElement e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "title" );
00653 if ( !e.isNull() && !e.text().isEmpty() )
00654 {
00655 m_title = e.text();
00656 }
00657 e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "description" );
00658 if ( !e.isNull() && !e.text().isEmpty() )
00659 {
00660 m_abstract = e.text();
00661 }
00662 e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "subject" );
00663 if ( !e.isNull() && !e.text().isEmpty() )
00664 {
00665 m_subject = e.text();
00666 }
00667 e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "keyword" );
00668 if ( !e.isNull() && !e.text().isEmpty() )
00669 {
00670 m_keywords = e.text();
00671 }
00672 return true;
00673 }
00674
00675
00676 bool KoDocumentInfoAbout::load( const QDomElement& e )
00677 {
00678 QDomNode n = e.namedItem( "about" ).firstChild();
00679 for( ; !n.isNull(); n = n.nextSibling() )
00680 {
00681 QDomElement e = n.toElement();
00682 if ( e.isNull() ) continue;
00683 if ( e.tagName() == "abstract" )
00684 m_abstract = e.text();
00685 else if ( e.tagName() == "title" )
00686 m_title = e.text();
00687 else if ( e.tagName() == "subject" )
00688 m_subject = e.text();
00689 else if ( e.tagName() == "keyword" )
00690 m_keywords = e.text();
00691 }
00692
00693 return true;
00694 }
00695
00696
00697 QDomElement KoDocumentInfoAbout::save( QDomDocument& doc )
00698 {
00699 QDomElement e = doc.createElement( "about" );
00700
00701 QDomElement t = doc.createElement( "abstract" );
00702 e.appendChild( t );
00703 t.appendChild( doc.createCDATASection( m_abstract ) );
00704
00705 t = doc.createElement( "title" );
00706 e.appendChild( t );
00707 t.appendChild( doc.createTextNode( m_title ) );
00708
00709 t = doc.createElement( "keyword" );
00710 e.appendChild( t );
00711 t.appendChild( doc.createTextNode( m_keywords ) );
00712
00713 t = doc.createElement( "subject" );
00714 e.appendChild( t );
00715 t.appendChild( doc.createTextNode( m_subject ) );
00716
00717 return e;
00718 }
00719
00720 QString KoDocumentInfoAbout::title() const
00721 {
00722 return m_title;
00723 }
00724
00725 QString KoDocumentInfoAbout::abstract() const
00726 {
00727 return m_abstract;
00728 }
00729
00730 void KoDocumentInfoAbout::setTitle( const QString& n )
00731 {
00732 m_title = n;
00733 }
00734
00735 void KoDocumentInfoAbout::setAbstract( const QString& n )
00736 {
00737 m_abstract = n;
00738 }
00739
00740 QString KoDocumentInfoAbout::keywords() const
00741 {
00742 return m_keywords;
00743 }
00744
00745 QString KoDocumentInfoAbout::subject() const
00746 {
00747 return m_subject;
00748 }
00749
00750 void KoDocumentInfoAbout::setKeywords( const QString& n )
00751 {
00752 m_keywords = n;
00753 }
00754
00755 void KoDocumentInfoAbout::setSubject( const QString& n )
00756 {
00757 m_subject = n;
00758 }
00759
00760
00761
00762 #include <koDocumentInfo.moc>
This file is part of the documentation for lib Library Version 1.4.2.