21#include "KoDocumentInfo.h"
23#include "KoDocument.h"
24#include "kofficeversion.h"
25#include "KoApplication.h"
27#include <KoStoreDevice.h>
28#include <KoXmlWriter.h>
35#include <tqobjectlist.h>
36#include <tqdatetime.h>
45KoDocumentInfo::KoDocumentInfo( TQObject* parent,
const char* name )
46 : TQObject( parent,
name )
48 (void)
new KoDocumentInfoUserMetadata(
this );
49 (void)
new KoDocumentInfoAuthor(
this );
50 (void)
new KoDocumentInfoAbout(
this );
53KoDocumentInfo::~KoDocumentInfo()
58bool KoDocumentInfo::load(
const TQDomDocument& doc )
60 TQStringList lst = pages();
61 TQStringList::ConstIterator it = lst.begin();
62 for( ; it != lst.end(); ++it )
64 KoDocumentInfoPage* p = page( *it );
66 if ( !p->load( doc.documentElement() ) )
73bool KoDocumentInfo::loadOasis(
const TQDomDocument& metaDoc )
76 TQStringList lst = pages();
77 TQStringList::ConstIterator it = lst.begin();
78 for( ; it != lst.end(); ++it )
80 KoDocumentInfoPage* p = page( *it );
86 if ( office.isNull() )
89 if ( !p->loadOasis( office ) )
96TQDomDocument KoDocumentInfo::save()
99 TQDomElement e = doc.documentElement();
101 const TQStringList lst = pages();
102 TQStringList::ConstIterator it = lst.begin();
103 for( ; it != lst.end(); ++it )
105 KoDocumentInfoPage* p = page( *it );
107 TQDomElement s = p->save( doc );
113 return TQDomDocument();
118bool KoDocumentInfo::saveOasis(
KoStore* store )
120 KoStoreDevice dev( store );
125 xmlWriter->
addTextNode( TQString(
"KOffice/%1" ).arg( KOFFICE_VERSION_STRING ) );
127 TQStringList lst = pages();
128 TQStringList::ConstIterator it = lst.begin();
129 for( ; it != lst.end(); ++it )
131 KoDocumentInfoPage* p = page( *it );
133 if ( !p->saveOasis( *xmlWriter ) )
143KoDocumentInfoPage* KoDocumentInfo::page(
const TQString& name )
const
145 TQObject* obj =
const_cast<KoDocumentInfo*
>(
this)->child(
name.latin1() );
147 return (KoDocumentInfoPage*)obj;
150TQStringList KoDocumentInfo::pages()
const
154 const TQObjectList list = childrenListObject();
155 if ( !list.isEmpty() )
157 TQObjectListIt it( list );
159 while ( ( obj = it.current() ) )
161 ret.prepend( obj->name() );
169TQString KoDocumentInfo::title()
const
171 KoDocumentInfoAbout * aboutPage =
static_cast<KoDocumentInfoAbout *
>(page(
"about" ));
173 kdWarning() <<
"'About' page not found in documentInfo !" << endl;
177 return aboutPage->title();
180TQString KoDocumentInfo::creator()
const
182 KoDocumentInfoAuthor * authorPage =
static_cast<KoDocumentInfoAuthor *
>(page(
"author" ));
184 kdWarning() <<
"'Author' page not found in documentInfo !" << endl;
188 return authorPage->fullName();
197KoDocumentInfoPage::KoDocumentInfoPage( TQObject* parent,
const char* name )
198 : TQObject( parent,
name )
208KoDocumentInfoAuthor::KoDocumentInfoAuthor( KoDocumentInfo* info )
209 : KoDocumentInfoPage( info,
"author" )
214KoDocumentInfoAuthor::~KoDocumentInfoAuthor()
218void KoDocumentInfoAuthor::initParameters()
220 TDEConfig* config = KoGlobal::kofficeConfig();
221 if ( config->hasGroup(
"Author" ) ) {
222 TDEConfigGroupSaver cgs( config,
"Author" );
223 m_telephoneHome=config->readEntry(
"telephone" );
224 m_telephoneWork=config->readEntry(
"telephone-work" );
225 m_fax=config->readEntry(
"fax" );
226 m_country=config->readEntry(
"country" );
227 m_postalCode=config->readEntry(
"postal-code" );
228 m_city=config->readEntry(
"city" );
229 m_street=config->readEntry(
"street" );
232 m_emailCfg =
new TDEConfig(
"emaildefaults",
true );
233 m_emailCfg->setGroup(
"Defaults" );
234 TQString group = m_emailCfg->readEntry(
"Profile",
"Default");
235 m_emailCfg->setGroup(TQString(
"PROFILE_%1").arg(group));
237 if ( m_fullName.isNull() )
239 TQString
name = m_emailCfg->readEntry(
"FullName" );
240 if ( !
name.isEmpty() )
243 if ( m_company.isNull() )
245 TQString
name = m_emailCfg->readEntry(
"Organization" );
246 if ( !
name.isEmpty() )
251bool KoDocumentInfoAuthor::saveOasis(
KoXmlWriter &xmlWriter )
253 if ( !m_fullName.isEmpty() )
259 if ( !m_initial.isEmpty() )
266 if ( !m_title.isEmpty() )
273 if ( !m_company.isEmpty() )
280 if ( !m_email.isEmpty() )
287 if ( !m_telephoneHome.isEmpty() )
294 if ( !m_telephoneWork.isEmpty() )
297 xmlWriter.
addAttribute(
"meta:name",
"telephone-work" );
301 if ( !m_fax.isEmpty() )
308 if ( !m_country.isEmpty() )
315 if ( !m_postalCode.isEmpty() )
322 if ( !m_city.isEmpty() )
329 if ( !m_street.isEmpty() )
336 if ( !m_position.isEmpty() )
346bool KoDocumentInfoAuthor::loadOasis(
const TQDomNode& metaDoc )
349 if ( !e.isNull() && !e.text().isEmpty() )
350 m_fullName = e.text();
351 TQDomNode n = metaDoc.firstChild();
352 for ( ; !n.isNull(); n = n.nextSibling() )
356 TQDomElement e = n.toElement();
357 if ( e.namespaceURI() == KoXmlNS::meta && e.localName() ==
"user-defined" && !e.text().isEmpty() )
359 TQString
name = e.attributeNS( KoXmlNS::meta,
"name", TQString() );
360 if ( name ==
"initial" )
361 m_initial = e.text();
362 else if ( name ==
"author-title" )
364 else if ( name ==
"company" )
365 m_company = e.text();
366 else if ( name ==
"email" )
368 else if ( name ==
"telephone" )
369 m_telephoneHome = e.text();
370 else if ( name ==
"telephone-work" )
371 m_telephoneWork = e.text();
372 else if ( name ==
"fax" )
374 else if ( name ==
"country" )
375 m_country = e.text();
376 else if ( name ==
"postal-code" )
377 m_postalCode = e.text();
378 else if ( name ==
"city" )
380 else if ( name ==
"street" )
382 else if ( name ==
"position" )
383 m_position = e.text();
391bool KoDocumentInfoAuthor::load(
const TQDomElement& e )
393 TQDomNode n = e.namedItem(
"author" ).firstChild();
394 for( ; !n.isNull(); n = n.nextSibling() )
396 TQDomElement e = n.toElement();
397 if ( e.isNull() )
continue;
398 if ( e.tagName() ==
"full-name" )
399 m_fullName = e.text();
400 else if ( e.tagName() ==
"initial" )
401 m_initial = e.text();
402 else if ( e.tagName() ==
"title" )
404 else if ( e.tagName() ==
"company" )
405 m_company = e.text();
406 else if ( e.tagName() ==
"email" )
408 else if ( e.tagName() ==
"telephone" )
409 m_telephoneHome = e.text();
410 else if ( e.tagName() ==
"telephone-work" )
411 m_telephoneWork = e.text();
412 else if ( e.tagName() ==
"fax" )
414 else if ( e.tagName() ==
"country" )
415 m_country = e.text();
416 else if ( e.tagName() ==
"postal-code" )
417 m_postalCode = e.text();
418 else if ( e.tagName() ==
"city" )
420 else if ( e.tagName() ==
"street" )
422 else if ( e.tagName() ==
"position" )
423 m_position = e.text();
428TQDomElement KoDocumentInfoAuthor::save( TQDomDocument& doc )
430 TQDomElement e = doc.createElement(
"author" );
432 TQDomElement t = doc.createElement(
"full-name" );
434 t.appendChild( doc.createTextNode( m_fullName ) );
436 t = doc.createElement(
"initial" );
438 t.appendChild( doc.createTextNode( m_initial ) );
441 t = doc.createElement(
"title" );
443 t.appendChild( doc.createTextNode( m_title ) );
445 t = doc.createElement(
"company" );
447 t.appendChild( doc.createTextNode( m_company ) );
449 t = doc.createElement(
"email" );
451 t.appendChild( doc.createTextNode( m_email ) );
453 t = doc.createElement(
"telephone" );
455 t.appendChild( doc.createTextNode( m_telephoneHome ) );
457 t = doc.createElement(
"telephone-work" );
459 t.appendChild( doc.createTextNode( m_telephoneWork ) );
461 t = doc.createElement(
"fax" );
463 t.appendChild( doc.createTextNode( m_fax ) );
465 t = doc.createElement(
"country" );
467 t.appendChild( doc.createTextNode( m_country ) );
469 t = doc.createElement(
"postal-code" );
471 t.appendChild( doc.createTextNode( m_postalCode ) );
473 t = doc.createElement(
"city" );
475 t.appendChild( doc.createTextNode( m_city ) );
477 t = doc.createElement(
"street" );
479 t.appendChild( doc.createTextNode( m_street ) );
481 t = doc.createElement(
"position" );
483 t.appendChild( doc.createTextNode( m_position ) );
488TQString KoDocumentInfoAuthor::fullName()
const
493TQString KoDocumentInfoAuthor::initial()
const
498TQString KoDocumentInfoAuthor::title()
const
503TQString KoDocumentInfoAuthor::company()
const
508TQString KoDocumentInfoAuthor::email()
const
513TQString KoDocumentInfoAuthor::telephoneHome()
const
515 return m_telephoneHome;
518TQString KoDocumentInfoAuthor::telephoneWork()
const
520 return m_telephoneWork;
523TQString KoDocumentInfoAuthor::fax()
const
528TQString KoDocumentInfoAuthor::country()
const
533TQString KoDocumentInfoAuthor::postalCode()
const
538TQString KoDocumentInfoAuthor::city()
const
543TQString KoDocumentInfoAuthor::street()
const
548TQString KoDocumentInfoAuthor::position()
const
553void KoDocumentInfoAuthor::setFullName(
const TQString& n )
558void KoDocumentInfoAuthor::setInitial(
const TQString& n )
563void KoDocumentInfoAuthor::setTitle(
const TQString& n )
568void KoDocumentInfoAuthor::setCompany(
const TQString& n )
573void KoDocumentInfoAuthor::setEmail(
const TQString& n )
578void KoDocumentInfoAuthor::setTelephoneHome(
const TQString& n )
583void KoDocumentInfoAuthor::setTelephoneWork(
const TQString& n )
588void KoDocumentInfoAuthor::setFax(
const TQString& n )
593void KoDocumentInfoAuthor::setCountry(
const TQString& n )
598void KoDocumentInfoAuthor::setPostalCode(
const TQString& n )
603void KoDocumentInfoAuthor::setCity(
const TQString& n )
608void KoDocumentInfoAuthor::setStreet(
const TQString& n )
613void KoDocumentInfoAuthor::setPosition(
const TQString& n )
625KoDocumentInfoAbout::KoDocumentInfoAbout( KoDocumentInfo* info )
626 : KoDocumentInfoPage( info,
"about" )
631 m_initialCreator = m_docInfo->creator();
632 m_creationDate = TQDateTime::currentDateTime();
635void KoDocumentInfoAbout::saveParameters()
637 KoDocument* doc =
dynamic_cast< KoDocument*
>( m_docInfo->parent() );
640 m_modificationDate = TQDateTime::currentDateTime();
644bool KoDocumentInfoAbout::saveOasis(
KoXmlWriter &xmlWriter )
647 if ( !m_title.isEmpty() )
653 if ( !m_abstract.isEmpty() )
659 if ( !m_keywords.isEmpty() )
665 if ( !m_subject.isEmpty() )
671 if ( !m_initialCreator.isEmpty() )
679 xmlWriter.
addTextNode( TQString::number( m_editingCycles ) );
682 if ( m_creationDate.isValid() )
685 xmlWriter.
addTextNode( m_creationDate.toString( TQt::ISODate ) );
689 if ( m_modificationDate.isValid() )
692 xmlWriter.
addTextNode( m_modificationDate.toString( TQt::ISODate ) );
698bool KoDocumentInfoAbout::loadOasis(
const TQDomNode& metaDoc )
701 if ( !e.isNull() && !e.text().isEmpty() )
706 if ( !e.isNull() && !e.text().isEmpty() )
708 m_abstract = e.text();
711 if ( !e.isNull() && !e.text().isEmpty() )
713 m_subject = e.text();
716 if ( !e.isNull() && !e.text().isEmpty() )
718 m_keywords = e.text();
721 if ( !e.isNull() && !e.text().isEmpty() )
722 m_initialCreator = e.text();
724 m_initialCreator = i18n(
"Unknown" );
727 if ( !e.isNull() && !e.text().isEmpty() )
728 m_editingCycles = e.text().toInt();
731 if ( !e.isNull() && !e.text().isEmpty() )
732 m_creationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
734 m_creationDate = TQDateTime();
737 if ( !e.isNull() && !e.text().isEmpty() )
738 m_modificationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
743bool KoDocumentInfoAbout::load(
const TQDomElement& e )
745 TQDomNode n = e.namedItem(
"about" ).firstChild();
746 for( ; !n.isNull(); n = n.nextSibling() )
748 TQDomElement e = n.toElement();
749 if ( e.isNull() )
continue;
750 if ( e.tagName() ==
"abstract" )
751 m_abstract = e.text();
752 else if ( e.tagName() ==
"title" )
754 else if ( e.tagName() ==
"subject" )
755 m_subject = e.text();
756 else if ( e.tagName() ==
"keyword" )
757 m_keywords = e.text();
758 else if ( e.tagName() ==
"initial-creator" )
759 m_initialCreator = e.text();
760 else if ( e.tagName() ==
"editing-cycles" )
761 m_editingCycles = e.text().toInt();
762 else if ( e.tagName() ==
"creation-date" )
763 m_creationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
764 else if ( e.tagName() ==
"date" )
765 m_modificationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
772TQDomElement KoDocumentInfoAbout::save( TQDomDocument& doc )
775 TQDomElement e = doc.createElement(
"about" );
777 TQDomElement t = doc.createElement(
"abstract" );
779 t.appendChild( doc.createCDATASection( m_abstract ) );
781 t = doc.createElement(
"title" );
783 t.appendChild( doc.createTextNode( m_title ) );
785 t = doc.createElement(
"keyword" );
787 t.appendChild( doc.createTextNode( m_keywords ) );
789 t = doc.createElement(
"subject" );
791 t.appendChild( doc.createTextNode( m_subject ) );
793 t = doc.createElement(
"initial-creator" );
795 t.appendChild( doc.createTextNode( m_initialCreator ) );
797 t = doc.createElement(
"editing-cycles" );
799 t.appendChild( doc.createTextNode( TQString::number( m_editingCycles ) ) );
801 t = doc.createElement(
"creation-date" );
803 t.appendChild( doc.createTextNode( m_creationDate.toString( TQt::ISODate ) ) );
805 t = doc.createElement(
"date" );
807 t.appendChild( doc.createTextNode( m_modificationDate.toString( TQt::ISODate ) ) );
811TQString KoDocumentInfoAbout::title()
const
816TQString KoDocumentInfoAbout::abstract()
const
821TQString KoDocumentInfoAbout::initialCreator()
const
823 return m_initialCreator;
826TQString KoDocumentInfoAbout::editingCycles()
const
828 return TQString::number( m_editingCycles );
831TQString KoDocumentInfoAbout::creationDate()
const
833 if ( m_creationDate.isValid() )
834 return TDEGlobal::locale()->formatDateTime( m_creationDate );
839TQString KoDocumentInfoAbout::modificationDate()
const
841 if ( m_modificationDate.isValid() )
842 return TDEGlobal::locale()->formatDateTime( m_modificationDate );
847void KoDocumentInfoAbout::setTitle(
const TQString& n )
852void KoDocumentInfoAbout::setAbstract(
const TQString& n )
857TQString KoDocumentInfoAbout::keywords()
const
862TQString KoDocumentInfoAbout::subject()
const
867void KoDocumentInfoAbout::setKeywords(
const TQString& n )
872void KoDocumentInfoAbout::setSubject(
const TQString& n )
877void KoDocumentInfoAbout::resetMetaData()
880 m_initialCreator = m_docInfo->creator();
881 m_creationDate = TQDateTime::currentDateTime();
882 m_modificationDate = TQDateTime();
891KoDocumentInfoUserMetadata::KoDocumentInfoUserMetadata( KoDocumentInfo* info )
892 : KoDocumentInfoPage( info,
"user_metadata" )
894 m_reserved <<
"initial" <<
"author-title" <<
"company" <<
"email" <<
"telephone"
895 <<
"telephone-work" <<
"fax" <<
"country" <<
"postal-code" <<
"city" <<
"street"
899bool KoDocumentInfoUserMetadata::saveOasis(
KoXmlWriter &xmlWriter )
901 TQMap<TQString, TQString>::iterator it;
902 for ( it = m_metaList.begin(); it != m_metaList.end(); ++it )
912bool KoDocumentInfoUserMetadata::loadOasis(
const TQDomNode& metaDoc )
914 TQDomNode n = metaDoc.firstChild();
915 for ( ; !n.isNull(); n = n.nextSibling() )
919 TQDomElement e = n.toElement();
920 if ( e.namespaceURI() == KoXmlNS::meta && e.localName() ==
"user-defined" && !e.text().isEmpty() )
922 TQString
name = e.attributeNS( KoXmlNS::meta,
"name", TQString() );
923 if ( !m_reserved.contains( name ) )
924 m_metaList[
name ] = e.text();
932bool KoDocumentInfoUserMetadata::load(
const TQDomElement& )
938TQDomElement KoDocumentInfoUserMetadata::save( TQDomDocument& )
940 return TQDomElement();
943#include <KoDocumentInfo.moc>
TQDomDocument createDomDocument(const TQString &tagName, const TQString &version) const
Return a correctly created TQDomDocument for this KoDocument, including processing instruction,...
bool isAutosaving() const
Checks whether the document is currently in the process of autosaving.
static KoXmlWriter * createOasisXmlWriter(TQIODevice *dev, const char *rootElementName)
Return an XML writer for saving Oasis XML into the device dev, including the XML processing instructi...
Saves and loads KOffice documents using various backends.
A class for writing out XML (to any TQIODevice), with a special attention on performance.
void startElement(const char *tagName, bool indentInside=true)
Start a new element, as a child of the current element.
void addTextNode(const TQString &str)
Overloaded version of addTextNode( const char* ), which is a bit slower because it needs to convert s...
void endDocument()
Call this to terminate an XML document.
void endElement()
Terminate the current element.
void addAttribute(const char *attrName, const TQString &value)
Overloaded version of addAttribute( const char*, const char* ), which is a bit slower because it need...
const char * name(StdAction id)
KOFFICECORE_EXPORT TQDomElement namedItemNS(const TQDomNode &node, const char *nsURI, const char *localName)
A namespace-aware version of TQDomNode::namedItem(), which also takes care of casting to a TQDomEleme...