2 // C++ Implementation: docbookclasses
7 // Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
14 #include <QtGui/QWidget>
15 #include <QtCore/QTextStream>
16 #include <QtGui/QPixmap>
17 #include <QtCore/QRegExp>
20 #include <QtCore/QFile>
26 #include <kiconloader.h>
27 #include <kmessagebox.h>
29 // App specific includes
30 #include "parasaxparser.h"
31 #include "docbookclasses.h"
33 //////////////////////////////////////
35 //////////////////////////////////////
36 ListViewInterface::ListViewInterface(ListViewInterface
*parent
, QString label
)
37 : K3ListViewItem( parent
, label
)
41 ListViewInterface::ListViewInterface(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
) : K3ListViewItem( parent
, after
, label
)
45 ListViewInterface::ListViewInterface(K3ListView
*lv
, QString label
)
46 : K3ListViewItem( lv
, label
)
51 //////////////////////////////////////
52 // Classes for Roberts elements
53 //////////////////////////////////////
57 RobDocument::RobDocument(K3ListView
*lv
, QString label
)
58 : ListViewInterface( lv
, label
)
60 QPixmap pixmap
= KIconLoader::global()->loadIcon("help-contents", K3Icon::Small
);
61 this->setPixmap(0, pixmap
);
65 RobDocument::~RobDocument()
69 QString
RobDocument::getRTFHeader() const
71 QString header
= "<H1><center>" + this->text(0) + "</center></H1>";
75 QString
RobDocument::getHeader() const
77 QString header
= this->text(0) + '\n';
83 //////////////////////////////////////
84 // Classes for Docbook elements
85 //////////////////////////////////////
89 Overview::Overview(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
90 : ListViewInterface(parent
, after
, label
)
92 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
93 this->setPixmap(0, pixmap
);
94 this->setText(3, "0"); // upmost element
102 QString
Overview::getRTFHeader() const
104 QString header
= "<H1>" + this->text(0) + "</H1>";
108 QString
Overview::getHeader() const
110 QString header
= this->text(0) + '\n';
118 Date::Date(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
119 : ListViewInterface(parent
, after
, label
)
121 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
122 this->setPixmap(0, pixmap
);
123 this->setText(3, "00000001");
125 m_iseditable
= false;
132 void Date::setNodes( const NodeList_type
&list
)
135 m_node
= list
.front();
138 void Date::getNodes( NodeList_type
&list
) const
140 list
.push_back( m_node
);
143 QString
Date::getRTFHeader() const
145 QString header
= "<B>" + this->text(0) + ": </B>";
149 QString
Date::getHeader() const
151 QString header
= this->text(0) + ": ";
155 QString
Date::getRTFData() const
157 if ( !m_node
.isNull() ){
158 QString date
= m_node
.nodeValue() + "<br>";
164 QString
Date::getData() const
166 if ( !m_node
.isNull() ){
167 return m_node
.nodeValue();
172 QString
Date::getRawData() const
176 // get content of element
177 QTextStream
in(&ret
, QIODevice::WriteOnly
);
178 in
.setEncoding(QTextStream::UnicodeUTF8
);
184 void Date::setData(const QString
&data
, QDomDocument
&)
186 m_node
.setNodeValue(data
);
187 this->setText(1, data
); // update ListView
194 ReleaseInfo::ReleaseInfo(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
195 : ListViewInterface(parent
, after
, label
)
197 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
198 this->setPixmap(0, pixmap
);
199 this->setText(3, "00000002");
201 m_iseditable
= false;
204 ReleaseInfo::~ReleaseInfo()
208 void ReleaseInfo::setNodes( const NodeList_type
&list
)
211 m_node
= list
.front();
214 void ReleaseInfo::getNodes( NodeList_type
&list
) const
216 list
.push_back( m_node
);
219 QString
ReleaseInfo::getRTFHeader() const
221 QString header
= "<B>" + this->text(0) + ": </B>";
225 QString
ReleaseInfo::getHeader() const
227 QString header
= this->text(0) + ": ";
231 QString
ReleaseInfo::getRTFData() const
233 if ( !m_node
.isNull() ){
234 QString releaseinfo
= m_node
.nodeValue() + "<br>";
240 QString
ReleaseInfo::getData() const
242 if ( !m_node
.isNull() ){
243 return m_node
.nodeValue();
248 QString
ReleaseInfo::getRawData() const
252 // get content of element
253 QTextStream
in(&ret
, QIODevice::WriteOnly
);
254 in
.setEncoding(QTextStream::UnicodeUTF8
);
260 void ReleaseInfo::setData(const QString
&data
, QDomDocument
&)
262 m_node
.setNodeValue(data
);
263 this->setText(1, data
); // update ListView
270 AuthorGroup::AuthorGroup(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
271 : ListViewInterface(parent
, after
, label
)
273 QPixmap pixmap
= KIconLoader::global()->loadIcon("kdmconfig", K3Icon::Small
);
274 this->setPixmap(0, pixmap
);
275 this->setText(3, "00000003");
276 m_iseditable
= false;
279 AuthorGroup::~AuthorGroup()
283 QString
AuthorGroup::getRTFHeader() const
285 QString header
= "<H2>" + this->text(0) + "</H2>";
289 QString
AuthorGroup::getHeader() const
291 QString header
= this->text(0) + '\n';
299 Author::Author(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
300 : ListViewInterface(parent
, after
, label
)
302 QPixmap pixmap
= KIconLoader::global()->loadIcon("personal", K3Icon::Small
);
303 this->setPixmap(0, pixmap
);
304 m_node1
= QDomNode();
305 m_node2
= QDomNode();
306 m_iseditable
= false;
313 void Author::setNodes( const NodeList_type
&list
)
315 NodeList_type l_list
= list
;
316 NodeList_type::iterator it
= l_list
.begin();
321 void Author::getNodes( NodeList_type
&list
) const
323 list
.push_back( m_node1
);
324 list
.push_back( m_node2
);
328 QString
Author::getRTFHeader() const
330 QString header
= "<B>" + this->text(0) + ": </B>";
334 QString
Author::getHeader() const
336 QString author
= this->text(0) + ": ";
340 QString
Author::getRTFData() const
342 QString ret
= QString();
343 if ( !m_node1
.isNull() ){
344 ret
= m_node1
.nodeValue() + ' ';
347 if ( !m_node2
.isNull() ){
348 ret
+= m_node2
.nodeValue() + "<br>";
353 QString
Author::getData() const
355 QString ret
= QString();
356 if ( !m_node1
.isNull() ){
357 ret
= m_node1
.nodeValue() + ' ';
360 if ( !m_node2
.isNull() ){
361 ret
+= m_node2
.nodeValue();
366 QString
Author::getRawData() const
368 QString ret
= QString();
369 if ( !m_node1
.isNull() ){
370 ret
= m_node1
.nodeValue() + ' ';
373 if ( !m_node2
.isNull() ){
374 ret
+= m_node2
.nodeValue();
379 void Author::setData(const QString
&data
, QDomDocument
&)
382 QString m_data
= data
;
383 m_data
.replace( QRegExp("\n"), "" ); // remove Newlines
384 m_data
.replace( QRegExp(" {2,}"), " " ); // remove multiple spaces
385 m_data
.replace( QRegExp("[\t|\r]{1,}"), ""); // remove Tabs
386 // split string "firstname surname"
387 QString firstname
= m_data
.section(' ', 0, 0);
388 QString surname
= m_data
.section(' ', 1, 1);
389 // update node elements
390 m_node1
.setNodeValue(firstname
);
391 m_node2
.setNodeValue(surname
);
393 this->setText(1, firstname
+ ' ' + surname
);
400 KeywordSet::KeywordSet(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
401 : ListViewInterface(parent
, after
, label
)
403 QPixmap pixmap
= KIconLoader::global()->loadIcon("txt", K3Icon::Small
);
404 this->setPixmap(0, pixmap
);
405 this->setText(3, "00000004");
406 m_iseditable
= false;
409 KeywordSet::~KeywordSet()
413 QString
KeywordSet::getRTFHeader() const
415 QString header
= "<H2>" + this->text(0) + "</H2>";
419 QString
KeywordSet::getHeader() const
421 QString header
= this->text(0) + '\n';
429 Keyword::Keyword(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
430 : ListViewInterface(parent
, after
, label
)
433 m_iseditable
= false;
440 void Keyword::setNodes( const NodeList_type
&list
)
443 m_node
= list
.front();
446 void Keyword::getNodes( NodeList_type
&list
) const
448 list
.push_back( m_node
);
451 QString
Keyword::getRTFData() const
453 if ( !m_node
.isNull() ){
454 QString keyword
= m_node
.nodeValue() + "<br>";
460 QString
Keyword::getData() const
462 if ( !m_node
.isNull() ){
463 return m_node
.nodeValue();
468 QString
Keyword::getRawData() const
472 // get content of element
473 QTextStream
in(&ret
, QIODevice::WriteOnly
);
474 in
.setEncoding(QTextStream::UnicodeUTF8
);
480 void Keyword::setData(const QString
&data
, QDomDocument
&)
482 m_node
.setNodeValue(data
);
483 this->setText(0, data
); // update ListView
490 Abstract::Abstract(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
491 : ListViewInterface(parent
, after
, label
)
493 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
494 this->setPixmap(0, pixmap
);
495 this->setText(3, "00000005");
496 m_iseditable
= false;
499 Abstract::~Abstract()
503 QString
Abstract::getRTFHeader() const
505 QString header
= "<H2>" + this->text(0) + "</H2>";
509 QString
Abstract::getHeader() const
511 QString header
= this->text(0) + '\n';
519 Para::Para(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
520 : ListViewInterface(parent
, after
, label
)
522 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
523 this->setPixmap(0, pixmap
);
525 m_iseditable
= false;
532 void Para::setNodes( const NodeList_type
&list
)
535 m_node
= list
.front();
538 void Para::getNodes( NodeList_type
&list
) const
540 list
.push_back( m_node
);
543 QString
Para::getRTFHeader() const
548 QString
Para::getHeader() const
550 QString header
= this->text(0) + '\n';
554 QString
Para::getRTFData() const
556 // get content of element
558 QTextStream
in(¶graph
, QIODevice::WriteOnly
);
559 in
.setEncoding(QTextStream::UnicodeUTF8
);
562 // delegate job to SAX-Parser
566 ParaSaxParser
*p
= ParaSaxParser::Instance();
567 p
->setData( paragraph
);
568 p
->getRTFText( data
);
569 ret
= "<p>" + data
+ "</p>";
574 QString
Para::getData() const
576 // get content of element
578 QTextStream
in(¶graph
, QIODevice::WriteOnly
);
579 in
.setEncoding(QTextStream::UnicodeUTF8
);
582 // delegate job to SAX-Parser
585 ParaSaxParser
*p
= ParaSaxParser::Instance();
586 p
->setData( paragraph
);
592 QString
Para::getRawData() const
596 // get content of element
597 QTextStream
in(&ret
, QIODevice::WriteOnly
);
598 in
.setEncoding(QTextStream::UnicodeUTF8
);
600 // remove opening and closing para-tags
601 ret
.replace( QRegExp("</?(para|Para|PARA)/?>"),"");
602 ret
.replace( QRegExp("^ "),"" );
603 ret
.replace( QRegExp("^\n"), "" );
608 void Para::setData(const QString
&data
, QDomDocument
&)
610 kDebug(100200) << "Para::setData()";
613 QString l_data
= "<para>\n" + data
+ "\n</para>";
615 // create a temporary document
617 QDomDocument tempDoc
;
618 if ( !tempDoc
.setContent(l_data
) ){
619 l_data
= "<para><![CDATA[\n" + data
+ "\n]]></para>";
621 if ( !tempDoc
.setContent(l_data
) ){
622 err
= i18n("Unable to make document persistent.");
627 err
= i18n("This paragraph contains mismatching tags. It will will be handled as CDATA.");
628 KMessageBox::information(0, err
, i18n("XML-Error"));
632 QDomNode parent
= m_node
.parentNode();
633 if ( parent
.isNull() ){
634 kDebug(100200) << "Para::setData(): Structural DocBook format error.";
639 parent
.replaceChild(tempDoc
, m_node
);
647 Chapter::Chapter(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
648 : ListViewInterface(parent
, after
, label
)
650 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
651 this->setPixmap(0, pixmap
);
652 m_iseditable
= false;
659 QString
Chapter::getRTFHeader() const
661 QString header
= "<H1>" + this->text(0) + "</H1>";
665 QString
Chapter::getHeader() const
667 QString header
= this->text(0) + '\n';
675 Sect1::Sect1(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
676 : ListViewInterface(parent
, after
, label
)
678 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
679 this->setPixmap(0, pixmap
);
680 m_iseditable
= false;
687 QString
Sect1::getRTFHeader() const
689 QString header
= "<H2>" + this->text(0) + "</H2>";
693 QString
Sect1::getHeader() const
695 QString header
= this->text(0) + '\n';
703 Sect2::Sect2(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
704 : ListViewInterface(parent
, after
, label
)
706 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
707 this->setPixmap(0, pixmap
);
708 m_iseditable
= false;
715 QString
Sect2::getRTFHeader() const
717 QString header
= "<H3>" + this->text(0) + "</H3>";
721 QString
Sect2::getHeader() const
723 QString header
= this->text(0) + '\n';
731 Sect3::Sect3(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
732 : ListViewInterface(parent
, after
, label
)
734 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
735 this->setPixmap(0, pixmap
);
736 m_iseditable
= false;
743 QString
Sect3::getRTFHeader() const
745 QString header
= "<B>" + this->text(0) + "</B><br>";
749 QString
Sect3::getHeader() const
751 QString header
= this->text(0) + '\n';
759 Sect4::Sect4(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
760 : ListViewInterface(parent
, after
, label
)
762 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
763 this->setPixmap(0, pixmap
);
764 m_iseditable
= false;
771 QString
Sect4::getRTFHeader() const
773 QString header
= "<B>" + this->text(0) + "</B><br>";
777 QString
Sect4::getHeader() const
779 QString header
= this->text(0) + '\n';
787 Sect5::Sect5(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
788 : ListViewInterface(parent
, after
, label
)
790 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
791 this->setPixmap(0, pixmap
);
792 m_iseditable
= false;
799 QString
Sect5::getRTFHeader() const
801 QString header
= "<B>" + this->text(0) + "</B><br>";
805 QString
Sect5::getHeader() const
807 QString header
= this->text(0) + '\n';