lib

KoDocumentInfo.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org>
3 Copyright (C) 2004 David Faure <faure@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "KoDocumentInfo.h"
22#include "KoDom.h"
23#include "KoDocument.h"
24#include "kofficeversion.h"
25#include "KoApplication.h"
26
27#include <KoStoreDevice.h>
28#include <KoXmlWriter.h>
29
30#include <tdeconfig.h>
31#include <kdebug.h>
32#include <tdeglobal.h>
33#include <tdelocale.h>
34
35#include <tqobjectlist.h>
36#include <tqdatetime.h>
37#include "KoXmlNS.h"
38
39/*****************************************
40 *
41 * KoDocumentInfo
42 *
43 *****************************************/
44
45KoDocumentInfo::KoDocumentInfo( TQObject* parent, const char* name )
46 : TQObject( parent, name )
47{
48 (void)new KoDocumentInfoUserMetadata( this );
49 (void)new KoDocumentInfoAuthor( this );
50 (void)new KoDocumentInfoAbout( this );
51}
52
53KoDocumentInfo::~KoDocumentInfo()
54{
55}
56
57// KOffice-1.3 format
58bool KoDocumentInfo::load( const TQDomDocument& doc )
59{
60 TQStringList lst = pages();
61 TQStringList::ConstIterator it = lst.begin();
62 for( ; it != lst.end(); ++it )
63 {
64 KoDocumentInfoPage* p = page( *it );
65 Q_ASSERT( p );
66 if ( !p->load( doc.documentElement() ) )
67 return false;
68 }
69
70 return true;
71}
72
73bool KoDocumentInfo::loadOasis( const TQDomDocument& metaDoc )
74{
75 //kdDebug()<<" metaDoc.toString() :"<<metaDoc.toString()<<endl;
76 TQStringList lst = pages();
77 TQStringList::ConstIterator it = lst.begin();
78 for( ; it != lst.end(); ++it )
79 {
80 KoDocumentInfoPage* p = page( *it );
81 Q_ASSERT( p );
82
83 TQDomNode meta = KoDom::namedItemNS( metaDoc, KoXmlNS::office, "document-meta" );
84 TQDomNode office = KoDom::namedItemNS( meta, KoXmlNS::office, "meta" );
85
86 if ( office.isNull() )
87 return false;
88
89 if ( !p->loadOasis( office ) )
90 return false;
91 }
92 return true;
93}
94
95// KOffice-1.3 format
96TQDomDocument KoDocumentInfo::save()
97{
98 TQDomDocument doc = KoDocument::createDomDocument( "document-info" /*DTD name*/, "document-info" /*tag name*/, "1.1" );
99 TQDomElement e = doc.documentElement();
100
101 const TQStringList lst = pages();
102 TQStringList::ConstIterator it = lst.begin();
103 for( ; it != lst.end(); ++it )
104 {
105 KoDocumentInfoPage* p = page( *it );
106 Q_ASSERT( p );
107 TQDomElement s = p->save( doc );
108 if ( s.isNull() )
109 continue;
110 e.appendChild( s );
111 }
112 if ( e.isNull() )
113 return TQDomDocument();
114
115 return doc;
116}
117
118bool KoDocumentInfo::saveOasis( KoStore* store )
119{
120 KoStoreDevice dev( store );
121 KoXmlWriter* xmlWriter = KoDocument::createOasisXmlWriter( &dev, "office:document-meta" );
122 xmlWriter->startElement( "office:meta" );
123
124 xmlWriter->startElement( "meta:generator");
125 xmlWriter->addTextNode( TQString( "KOffice/%1" ).arg( KOFFICE_VERSION_STRING ) );
126 xmlWriter->endElement();
127 TQStringList lst = pages();
128 TQStringList::ConstIterator it = lst.begin();
129 for( ; it != lst.end(); ++it )
130 {
131 KoDocumentInfoPage* p = page( *it );
132 Q_ASSERT( p );
133 if ( !p->saveOasis( *xmlWriter ) )
134 return false;
135 }
136 xmlWriter->endElement();
137 xmlWriter->endElement(); // root element
138 xmlWriter->endDocument();
139 delete xmlWriter;
140 return true;
141}
142
143KoDocumentInfoPage* KoDocumentInfo::page( const TQString& name ) const
144{
145 TQObject* obj = const_cast<KoDocumentInfo*>(this)->child( name.latin1() );
146
147 return (KoDocumentInfoPage*)obj;
148}
149
150TQStringList KoDocumentInfo::pages() const
151{
152 TQStringList ret;
153
154 const TQObjectList list = childrenListObject();
155 if ( !list.isEmpty() )
156 {
157 TQObjectListIt it( list );
158 TQObject *obj;
159 while ( ( obj = it.current() ) )
160 {
161 ret.prepend( obj->name() );
162 ++it;
163 }
164 }
165
166 return ret;
167}
168
169TQString KoDocumentInfo::title() const
170{
171 KoDocumentInfoAbout * aboutPage = static_cast<KoDocumentInfoAbout *>(page( "about" ));
172 if ( !aboutPage ) {
173 kdWarning() << "'About' page not found in documentInfo !" << endl;
174 return TQString();
175 }
176 else
177 return aboutPage->title();
178}
179
180TQString KoDocumentInfo::creator() const
181{
182 KoDocumentInfoAuthor * authorPage = static_cast<KoDocumentInfoAuthor *>(page( "author" ));
183 if ( !authorPage ) {
184 kdWarning() << "'Author' page not found in documentInfo !" << endl;
185 return TQString();
186 }
187 else
188 return authorPage->fullName();
189}
190
191/*****************************************
192 *
193 * KoDocumentInfoPage
194 *
195 *****************************************/
196
197KoDocumentInfoPage::KoDocumentInfoPage( TQObject* parent, const char* name )
198 : TQObject( parent, name )
199{
200}
201
202/*****************************************
203 *
204 * KoDocumentInfoAuthor
205 *
206 *****************************************/
207
208KoDocumentInfoAuthor::KoDocumentInfoAuthor( KoDocumentInfo* info )
209 : KoDocumentInfoPage( info, "author" )
210{
211 initParameters();
212}
213
214KoDocumentInfoAuthor::~KoDocumentInfoAuthor()
215{
216 delete m_emailCfg;
217}
218void KoDocumentInfoAuthor::initParameters()
219{
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" );
230 }
231
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));
236
237 if ( m_fullName.isNull() ) // only if null. Empty means the user made it explicitly empty.
238 {
239 TQString name = m_emailCfg->readEntry( "FullName" );
240 if ( !name.isEmpty() )
241 m_fullName = name;
242 }
243 if ( m_company.isNull() )
244 {
245 TQString name = m_emailCfg->readEntry( "Organization" );
246 if ( !name.isEmpty() )
247 m_company = name;
248 }
249}
250
251bool KoDocumentInfoAuthor::saveOasis( KoXmlWriter &xmlWriter )
252{
253 if ( !m_fullName.isEmpty() )
254 {
255 xmlWriter.startElement( "dc:creator");
256 xmlWriter.addTextNode( m_fullName );
257 xmlWriter.endElement();
258 }
259 if ( !m_initial.isEmpty() )
260 {
261 xmlWriter.startElement( "meta:user-defined");
262 xmlWriter.addAttribute( "meta:name", "initial" );
263 xmlWriter.addTextNode( m_initial );
264 xmlWriter.endElement();
265 }
266 if ( !m_title.isEmpty() )
267 {
268 xmlWriter.startElement( "meta:user-defined");
269 xmlWriter.addAttribute( "meta:name", "author-title" );
270 xmlWriter.addTextNode( m_title );
271 xmlWriter.endElement();
272 }
273 if ( !m_company.isEmpty() )
274 {
275 xmlWriter.startElement( "meta:user-defined");
276 xmlWriter.addAttribute( "meta:name", "company" );
277 xmlWriter.addTextNode( m_company );
278 xmlWriter.endElement();
279 }
280 if ( !m_email.isEmpty() )
281 {
282 xmlWriter.startElement( "meta:user-defined");
283 xmlWriter.addAttribute( "meta:name", "email" );
284 xmlWriter.addTextNode( m_email );
285 xmlWriter.endElement();
286 }
287 if ( !m_telephoneHome.isEmpty() )
288 {
289 xmlWriter.startElement( "meta:user-defined");
290 xmlWriter.addAttribute( "meta:name", "telephone" );
291 xmlWriter.addTextNode( m_telephoneHome );
292 xmlWriter.endElement();
293 }
294 if ( !m_telephoneWork.isEmpty() )
295 {
296 xmlWriter.startElement( "meta:user-defined");
297 xmlWriter.addAttribute( "meta:name", "telephone-work" );
298 xmlWriter.addTextNode( m_telephoneWork );
299 xmlWriter.endElement();
300 }
301 if ( !m_fax.isEmpty() )
302 {
303 xmlWriter.startElement( "meta:user-defined");
304 xmlWriter.addAttribute( "meta:name", "fax" );
305 xmlWriter.addTextNode( m_fax );
306 xmlWriter.endElement();
307 }
308 if ( !m_country.isEmpty() )
309 {
310 xmlWriter.startElement( "meta:user-defined");
311 xmlWriter.addAttribute( "meta:name", "country" );
312 xmlWriter.addTextNode( m_country );
313 xmlWriter.endElement();
314 }
315 if ( !m_postalCode.isEmpty() )
316 {
317 xmlWriter.startElement( "meta:user-defined");
318 xmlWriter.addAttribute( "meta:name", "postal-code" );
319 xmlWriter.addTextNode( m_postalCode );
320 xmlWriter.endElement();
321 }
322 if ( !m_city.isEmpty() )
323 {
324 xmlWriter.startElement( "meta:user-defined");
325 xmlWriter.addAttribute( "meta:name", "city" );
326 xmlWriter.addTextNode( m_city );
327 xmlWriter.endElement();
328 }
329 if ( !m_street.isEmpty() )
330 {
331 xmlWriter.startElement( "meta:user-defined");
332 xmlWriter.addAttribute( "meta:name", "street" );
333 xmlWriter.addTextNode( m_street );
334 xmlWriter.endElement();
335 }
336 if ( !m_position.isEmpty() )
337 {
338 xmlWriter.startElement( "meta:user-defined");
339 xmlWriter.addAttribute( "meta:name", "position" );
340 xmlWriter.addTextNode( m_position );
341 xmlWriter.endElement();
342 }
343 return true;
344}
345
346bool KoDocumentInfoAuthor::loadOasis( const TQDomNode& metaDoc )
347{
348 TQDomElement e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "creator" );
349 if ( !e.isNull() && !e.text().isEmpty() )
350 m_fullName = e.text();
351 TQDomNode n = metaDoc.firstChild();
352 for ( ; !n.isNull(); n = n.nextSibling() )
353 {
354 if (n.isElement())
355 {
356 TQDomElement e = n.toElement();
357 if ( e.namespaceURI() == KoXmlNS::meta && e.localName() == "user-defined" && !e.text().isEmpty() )
358 {
359 TQString name = e.attributeNS( KoXmlNS::meta, "name", TQString() );
360 if ( name == "initial" )
361 m_initial = e.text();
362 else if ( name == "author-title" )
363 m_title = e.text();
364 else if ( name == "company" )
365 m_company = e.text();
366 else if ( name == "email" )
367 m_email = e.text();
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" )
373 m_fax = e.text();
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" )
379 m_city = e.text();
380 else if ( name == "street" )
381 m_street = e.text();
382 else if ( name == "position" )
383 m_position = e.text();
384 }
385 }
386 }
387 return true;
388}
389
390// KOffice-1.3 format
391bool KoDocumentInfoAuthor::load( const TQDomElement& e )
392{
393 TQDomNode n = e.namedItem( "author" ).firstChild();
394 for( ; !n.isNull(); n = n.nextSibling() )
395 {
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" )
403 m_title = e.text();
404 else if ( e.tagName() == "company" )
405 m_company = e.text();
406 else if ( e.tagName() == "email" )
407 m_email = e.text();
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" )
413 m_fax = e.text();
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" )
419 m_city = e.text();
420 else if ( e.tagName() == "street" )
421 m_street = e.text();
422 else if ( e.tagName() == "position" )
423 m_position = e.text();
424 }
425 return true;
426}
427
428TQDomElement KoDocumentInfoAuthor::save( TQDomDocument& doc )
429{
430 TQDomElement e = doc.createElement( "author" );
431
432 TQDomElement t = doc.createElement( "full-name" );
433 e.appendChild( t );
434 t.appendChild( doc.createTextNode( m_fullName ) );
435
436 t = doc.createElement( "initial" );
437 e.appendChild( t );
438 t.appendChild( doc.createTextNode( m_initial ) );
439
440
441 t = doc.createElement( "title" );
442 e.appendChild( t );
443 t.appendChild( doc.createTextNode( m_title ) );
444
445 t = doc.createElement( "company" );
446 e.appendChild( t );
447 t.appendChild( doc.createTextNode( m_company ) );
448
449 t = doc.createElement( "email" );
450 e.appendChild( t );
451 t.appendChild( doc.createTextNode( m_email ) );
452
453 t = doc.createElement( "telephone" );
454 e.appendChild( t );
455 t.appendChild( doc.createTextNode( m_telephoneHome ) );
456
457 t = doc.createElement( "telephone-work" );
458 e.appendChild( t );
459 t.appendChild( doc.createTextNode( m_telephoneWork ) );
460
461 t = doc.createElement( "fax" );
462 e.appendChild( t );
463 t.appendChild( doc.createTextNode( m_fax ) );
464
465 t = doc.createElement( "country" );
466 e.appendChild( t );
467 t.appendChild( doc.createTextNode( m_country ) );
468
469 t = doc.createElement( "postal-code" );
470 e.appendChild( t );
471 t.appendChild( doc.createTextNode( m_postalCode ) );
472
473 t = doc.createElement( "city" );
474 e.appendChild( t );
475 t.appendChild( doc.createTextNode( m_city ) );
476
477 t = doc.createElement( "street" );
478 e.appendChild( t );
479 t.appendChild( doc.createTextNode( m_street ) );
480
481 t = doc.createElement( "position" );
482 e.appendChild( t );
483 t.appendChild( doc.createTextNode( m_position ) );
484
485 return e;
486}
487
488TQString KoDocumentInfoAuthor::fullName() const
489{
490 return m_fullName;
491}
492
493TQString KoDocumentInfoAuthor::initial() const
494{
495 return m_initial;
496}
497
498TQString KoDocumentInfoAuthor::title() const
499{
500 return m_title;
501}
502
503TQString KoDocumentInfoAuthor::company() const
504{
505 return m_company;
506}
507
508TQString KoDocumentInfoAuthor::email() const
509{
510 return m_email;
511}
512
513TQString KoDocumentInfoAuthor::telephoneHome() const
514{
515 return m_telephoneHome;
516}
517
518TQString KoDocumentInfoAuthor::telephoneWork() const
519{
520 return m_telephoneWork;
521}
522
523TQString KoDocumentInfoAuthor::fax() const
524{
525 return m_fax;
526}
527
528TQString KoDocumentInfoAuthor::country() const
529{
530 return m_country;
531}
532
533TQString KoDocumentInfoAuthor::postalCode() const
534{
535 return m_postalCode;
536}
537
538TQString KoDocumentInfoAuthor::city() const
539{
540 return m_city;
541}
542
543TQString KoDocumentInfoAuthor::street() const
544{
545 return m_street;
546}
547
548TQString KoDocumentInfoAuthor::position() const
549{
550 return m_position;
551}
552
553void KoDocumentInfoAuthor::setFullName( const TQString& n )
554{
555 m_fullName = n;
556}
557
558void KoDocumentInfoAuthor::setInitial( const TQString& n )
559{
560 m_initial = n;
561}
562
563void KoDocumentInfoAuthor::setTitle( const TQString& n )
564{
565 m_title = n;
566}
567
568void KoDocumentInfoAuthor::setCompany( const TQString& n )
569{
570 m_company = n;
571}
572
573void KoDocumentInfoAuthor::setEmail( const TQString& n )
574{
575 m_email = n;
576}
577
578void KoDocumentInfoAuthor::setTelephoneHome( const TQString& n )
579{
580 m_telephoneHome = n;
581}
582
583void KoDocumentInfoAuthor::setTelephoneWork( const TQString& n )
584{
585 m_telephoneWork = n;
586}
587
588void KoDocumentInfoAuthor::setFax( const TQString& n )
589{
590 m_fax = n;
591}
592
593void KoDocumentInfoAuthor::setCountry( const TQString& n )
594{
595 m_country = n;
596}
597
598void KoDocumentInfoAuthor::setPostalCode( const TQString& n )
599{
600 m_postalCode = n;
601}
602
603void KoDocumentInfoAuthor::setCity( const TQString& n )
604{
605 m_city = n;
606}
607
608void KoDocumentInfoAuthor::setStreet( const TQString& n )
609{
610 m_street = n;
611}
612
613void KoDocumentInfoAuthor::setPosition( const TQString& n )
614{
615 m_position = n;
616}
617
618
619/*****************************************
620 *
621 * KoDocumentInfoAbout
622 *
623 *****************************************/
624
625KoDocumentInfoAbout::KoDocumentInfoAbout( KoDocumentInfo* info )
626 : KoDocumentInfoPage( info, "about" )
627{
628 m_firstSave = true;
629 m_docInfo = info;
630 m_editingCycles = 0;
631 m_initialCreator = m_docInfo->creator();
632 m_creationDate = TQDateTime::currentDateTime();
633}
634
635void KoDocumentInfoAbout::saveParameters()
636{
637 KoDocument* doc = dynamic_cast< KoDocument* >( m_docInfo->parent() );
638 if ( m_firstSave && doc && !doc->isAutosaving() )
639 m_editingCycles++;
640 m_modificationDate = TQDateTime::currentDateTime();
641 m_firstSave = false;
642}
643
644bool KoDocumentInfoAbout::saveOasis( KoXmlWriter &xmlWriter )
645{
646 saveParameters();
647 if ( !m_title.isEmpty() )
648 {
649 xmlWriter.startElement( "dc:title" );
650 xmlWriter.addTextNode( m_title );
651 xmlWriter.endElement();
652 }
653 if ( !m_abstract.isEmpty() )
654 {
655 xmlWriter.startElement( "dc:description" );
656 xmlWriter.addTextNode( m_abstract );
657 xmlWriter.endElement();
658 }
659 if ( !m_keywords.isEmpty() )
660 {
661 xmlWriter.startElement( "meta:keyword" );
662 xmlWriter.addTextNode( m_keywords );
663 xmlWriter.endElement();
664 }
665 if ( !m_subject.isEmpty() )
666 {
667 xmlWriter.startElement( "dc:subject" );
668 xmlWriter.addTextNode( m_subject );
669 xmlWriter.endElement();
670 }
671 if ( !m_initialCreator.isEmpty() )
672 {
673 xmlWriter.startElement( "meta:initial-creator" );
674 xmlWriter.addTextNode( m_initialCreator );
675 xmlWriter.endElement();
676 }
677
678 xmlWriter.startElement( "meta:editing-cycles" );
679 xmlWriter.addTextNode( TQString::number( m_editingCycles ) );
680 xmlWriter.endElement();
681
682 if ( m_creationDate.isValid() )
683 {
684 xmlWriter.startElement( "meta:creation-date" );
685 xmlWriter.addTextNode( m_creationDate.toString( TQt::ISODate ) );
686 xmlWriter.endElement();
687 }
688
689 if ( m_modificationDate.isValid() )
690 {
691 xmlWriter.startElement( "dc:date" );
692 xmlWriter.addTextNode( m_modificationDate.toString( TQt::ISODate ) );
693 xmlWriter.endElement();
694 }
695 return true;
696}
697
698bool KoDocumentInfoAbout::loadOasis( const TQDomNode& metaDoc )
699{
700 TQDomElement e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "title" );
701 if ( !e.isNull() && !e.text().isEmpty() )
702 {
703 m_title = e.text();
704 }
705 e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "description" );
706 if ( !e.isNull() && !e.text().isEmpty() )
707 {
708 m_abstract = e.text();
709 }
710 e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "subject" );
711 if ( !e.isNull() && !e.text().isEmpty() )
712 {
713 m_subject = e.text();
714 }
715 e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "keyword" );
716 if ( !e.isNull() && !e.text().isEmpty() )
717 {
718 m_keywords = e.text();
719 }
720 e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "initial-creator" );
721 if ( !e.isNull() && !e.text().isEmpty() )
722 m_initialCreator = e.text();
723 else
724 m_initialCreator = i18n( "Unknown" );
725
726 e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "editing-cycles" );
727 if ( !e.isNull() && !e.text().isEmpty() )
728 m_editingCycles = e.text().toInt();
729
730 e = KoDom::namedItemNS( metaDoc, KoXmlNS::meta, "creation-date" );
731 if ( !e.isNull() && !e.text().isEmpty() )
732 m_creationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
733 else
734 m_creationDate = TQDateTime();
735
736 e = KoDom::namedItemNS( metaDoc, KoXmlNS::dc, "date" );
737 if ( !e.isNull() && !e.text().isEmpty() )
738 m_modificationDate = TQDateTime::fromString( e.text(), TQt::ISODate );
739 return true;
740}
741
742// KOffice-1.3 format
743bool KoDocumentInfoAbout::load( const TQDomElement& e )
744{
745 TQDomNode n = e.namedItem( "about" ).firstChild();
746 for( ; !n.isNull(); n = n.nextSibling() )
747 {
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" )
753 m_title = e.text();
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 );
766 }
767
768 return true;
769}
770
771// KOffice-1.3 format
772TQDomElement KoDocumentInfoAbout::save( TQDomDocument& doc )
773{
774 saveParameters();
775 TQDomElement e = doc.createElement( "about" );
776
777 TQDomElement t = doc.createElement( "abstract" );
778 e.appendChild( t );
779 t.appendChild( doc.createCDATASection( m_abstract ) );
780
781 t = doc.createElement( "title" );
782 e.appendChild( t );
783 t.appendChild( doc.createTextNode( m_title ) );
784
785 t = doc.createElement( "keyword" );
786 e.appendChild( t );
787 t.appendChild( doc.createTextNode( m_keywords ) );
788
789 t = doc.createElement( "subject" );
790 e.appendChild( t );
791 t.appendChild( doc.createTextNode( m_subject ) );
792
793 t = doc.createElement( "initial-creator" );
794 e.appendChild( t );
795 t.appendChild( doc.createTextNode( m_initialCreator ) );
796
797 t = doc.createElement( "editing-cycles" );
798 e.appendChild( t );
799 t.appendChild( doc.createTextNode( TQString::number( m_editingCycles ) ) );
800
801 t = doc.createElement( "creation-date" );
802 e.appendChild( t );
803 t.appendChild( doc.createTextNode( m_creationDate.toString( TQt::ISODate ) ) );
804
805 t = doc.createElement( "date" );
806 e.appendChild( t );
807 t.appendChild( doc.createTextNode( m_modificationDate.toString( TQt::ISODate ) ) );
808 return e;
809}
810
811TQString KoDocumentInfoAbout::title() const
812{
813 return m_title;
814}
815
816TQString KoDocumentInfoAbout::abstract() const
817{
818 return m_abstract;
819}
820
821TQString KoDocumentInfoAbout::initialCreator() const
822{
823 return m_initialCreator;
824}
825
826TQString KoDocumentInfoAbout::editingCycles() const
827{
828 return TQString::number( m_editingCycles );
829}
830
831TQString KoDocumentInfoAbout::creationDate() const
832{
833 if ( m_creationDate.isValid() )
834 return TDEGlobal::locale()->formatDateTime( m_creationDate );
835 else
836 return TQString();
837}
838
839TQString KoDocumentInfoAbout::modificationDate() const
840{
841 if ( m_modificationDate.isValid() )
842 return TDEGlobal::locale()->formatDateTime( m_modificationDate );
843 else
844 return TQString();
845}
846
847void KoDocumentInfoAbout::setTitle( const TQString& n )
848{
849 m_title = n;
850}
851
852void KoDocumentInfoAbout::setAbstract( const TQString& n )
853{
854 m_abstract = n;
855}
856
857TQString KoDocumentInfoAbout::keywords() const
858{
859 return m_keywords;
860}
861
862TQString KoDocumentInfoAbout::subject() const
863{
864 return m_subject;
865}
866
867void KoDocumentInfoAbout::setKeywords( const TQString& n )
868{
869 m_keywords = n;
870}
871
872void KoDocumentInfoAbout::setSubject( const TQString& n )
873{
874 m_subject = n;
875}
876
877void KoDocumentInfoAbout::resetMetaData()
878{
879 m_editingCycles = 0;
880 m_initialCreator = m_docInfo->creator();
881 m_creationDate = TQDateTime::currentDateTime();
882 m_modificationDate = TQDateTime();
883}
884
885/*****************************************
886 *
887 * KoDocumentInfoUserMetadata
888 *
889 *****************************************/
890
891KoDocumentInfoUserMetadata::KoDocumentInfoUserMetadata( KoDocumentInfo* info )
892 : KoDocumentInfoPage( info, "user_metadata" )
893{
894 m_reserved << "initial" << "author-title" << "company" << "email" << "telephone"
895 << "telephone-work" << "fax" << "country" << "postal-code" << "city" << "street"
896 << "position";
897}
898
899bool KoDocumentInfoUserMetadata::saveOasis( KoXmlWriter &xmlWriter )
900{
901 TQMap<TQString, TQString>::iterator it;
902 for ( it = m_metaList.begin(); it != m_metaList.end(); ++it )
903 {
904 xmlWriter.startElement( "meta:user-defined");
905 xmlWriter.addAttribute( "meta:name", it.key() );
906 xmlWriter.addTextNode( it.data() );
907 xmlWriter.endElement();
908 }
909 return true;
910}
911
912bool KoDocumentInfoUserMetadata::loadOasis( const TQDomNode& metaDoc )
913{
914 TQDomNode n = metaDoc.firstChild();
915 for ( ; !n.isNull(); n = n.nextSibling() )
916 {
917 if (n.isElement())
918 {
919 TQDomElement e = n.toElement();
920 if ( e.namespaceURI() == KoXmlNS::meta && e.localName() == "user-defined" && !e.text().isEmpty() )
921 {
922 TQString name = e.attributeNS( KoXmlNS::meta, "name", TQString() );
923 if ( !m_reserved.contains( name ) )
924 m_metaList[ name ] = e.text();
925 }
926 }
927 }
928 return true;
929}
930
931// KOffice-1.3 format
932bool KoDocumentInfoUserMetadata::load( const TQDomElement& )
933{
934 return true;
935}
936
937// KOffice-1.3 format
938TQDomElement KoDocumentInfoUserMetadata::save( TQDomDocument& )
939{
940 return TQDomElement();
941}
942
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.
Definition KoStore.h:40
A class for writing out XML (to any TQIODevice), with a special attention on performance.
Definition KoXmlWriter.h:37
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...
Definition KoXmlWriter.h:76
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...
Definition KoDom.cpp:22