2 // C++ Implementation: docbookclasses
7 // Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
9 // Copyright: See COPYING file that comes with this distribution
14 #include <QTextStream>
26 #include <kiconloader.h>
27 #include <kmessagebox.h>
29 // App specific includes
30 #include "parasaxparser.h"
31 #include "docbookclasses.h"
34 //////////////////////////////////////
36 //////////////////////////////////////
37 ListViewInterface::ListViewInterface(ListViewInterface
*parent
, QString label
)
38 : K3ListViewItem( parent
, label
)
42 ListViewInterface::ListViewInterface(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
) : K3ListViewItem( parent
, after
, label
)
46 ListViewInterface::ListViewInterface(K3ListView
*lv
, QString label
)
47 : K3ListViewItem( lv
, label
)
52 //////////////////////////////////////
53 // Classes for Roberts elements
54 //////////////////////////////////////
58 RobDocument::RobDocument(K3ListView
*lv
, QString label
)
59 : ListViewInterface( lv
, label
)
61 QPixmap pixmap
= KIconLoader::global()->loadIcon("help-contents", K3Icon::Small
);
62 this->setPixmap(0, pixmap
);
66 RobDocument::~RobDocument()
70 QString
RobDocument::getRTFHeader() const
72 QString header
= "<H1><center>" + this->text(0) + "</center></H1>";
76 QString
RobDocument::getHeader() const
78 QString header
= this->text(0) + '\n';
84 //////////////////////////////////////
85 // Classes for Docbook elements
86 //////////////////////////////////////
90 Overview::Overview(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
91 : ListViewInterface(parent
, after
, label
)
93 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
94 this->setPixmap(0, pixmap
);
95 this->setText(3, "0"); // upmost element
103 QString
Overview::getRTFHeader() const
105 QString header
= "<H1>" + this->text(0) + "</H1>";
109 QString
Overview::getHeader() const
111 QString header
= this->text(0) + '\n';
119 Date::Date(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
120 : ListViewInterface(parent
, after
, label
)
122 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
123 this->setPixmap(0, pixmap
);
124 this->setText(3, "00000001");
126 m_iseditable
= false;
133 void Date::setNodes( const NodeList_type
&list
)
136 m_node
= list
.front();
139 void Date::getNodes( NodeList_type
&list
) const
141 list
.push_back( m_node
);
144 QString
Date::getRTFHeader() const
146 QString header
= "<B>" + this->text(0) + ": </B>";
150 QString
Date::getHeader() const
152 QString header
= this->text(0) + ": ";
156 QString
Date::getRTFData() const
158 if ( !m_node
.isNull() ){
159 QString date
= m_node
.nodeValue() + "<br>";
165 QString
Date::getData() const
167 if ( !m_node
.isNull() ){
168 return m_node
.nodeValue();
173 QString
Date::getRawData() const
177 // get content of element
178 QTextStream
in(&ret
, QIODevice::WriteOnly
);
179 in
.setEncoding(QTextStream::UnicodeUTF8
);
185 void Date::setData(const QString
&data
, QDomDocument
&)
187 m_node
.setNodeValue(data
);
188 this->setText(1, data
); // update ListView
195 ReleaseInfo::ReleaseInfo(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
196 : ListViewInterface(parent
, after
, label
)
198 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
199 this->setPixmap(0, pixmap
);
200 this->setText(3, "00000002");
202 m_iseditable
= false;
205 ReleaseInfo::~ReleaseInfo()
209 void ReleaseInfo::setNodes( const NodeList_type
&list
)
212 m_node
= list
.front();
215 void ReleaseInfo::getNodes( NodeList_type
&list
) const
217 list
.push_back( m_node
);
220 QString
ReleaseInfo::getRTFHeader() const
222 QString header
= "<B>" + this->text(0) + ": </B>";
226 QString
ReleaseInfo::getHeader() const
228 QString header
= this->text(0) + ": ";
232 QString
ReleaseInfo::getRTFData() const
234 if ( !m_node
.isNull() ){
235 QString releaseinfo
= m_node
.nodeValue() + "<br>";
241 QString
ReleaseInfo::getData() const
243 if ( !m_node
.isNull() ){
244 return m_node
.nodeValue();
249 QString
ReleaseInfo::getRawData() const
253 // get content of element
254 QTextStream
in(&ret
, QIODevice::WriteOnly
);
255 in
.setEncoding(QTextStream::UnicodeUTF8
);
261 void ReleaseInfo::setData(const QString
&data
, QDomDocument
&)
263 m_node
.setNodeValue(data
);
264 this->setText(1, data
); // update ListView
271 AuthorGroup::AuthorGroup(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
272 : ListViewInterface(parent
, after
, label
)
274 QPixmap pixmap
= KIconLoader::global()->loadIcon("kdmconfig", K3Icon::Small
);
275 this->setPixmap(0, pixmap
);
276 this->setText(3, "00000003");
277 m_iseditable
= false;
280 AuthorGroup::~AuthorGroup()
284 QString
AuthorGroup::getRTFHeader() const
286 QString header
= "<H2>" + this->text(0) + "</H2>";
290 QString
AuthorGroup::getHeader() const
292 QString header
= this->text(0) + '\n';
300 Author::Author(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
301 : ListViewInterface(parent
, after
, label
)
303 QPixmap pixmap
= KIconLoader::global()->loadIcon("personal", K3Icon::Small
);
304 this->setPixmap(0, pixmap
);
305 m_node1
= QDomNode();
306 m_node2
= QDomNode();
307 m_iseditable
= false;
314 void Author::setNodes( const NodeList_type
&list
)
316 NodeList_type l_list
= list
;
317 NodeList_type::iterator it
= l_list
.begin();
322 void Author::getNodes( NodeList_type
&list
) const
324 list
.push_back( m_node1
);
325 list
.push_back( m_node2
);
329 QString
Author::getRTFHeader() const
331 QString header
= "<B>" + this->text(0) + ": </B>";
335 QString
Author::getHeader() const
337 QString author
= this->text(0) + ": ";
341 QString
Author::getRTFData() const
343 QString ret
= QString();
344 if ( !m_node1
.isNull() ){
345 ret
= m_node1
.nodeValue() + ' ';
348 if ( !m_node2
.isNull() ){
349 ret
+= m_node2
.nodeValue() + "<br>";
354 QString
Author::getData() const
356 QString ret
= QString();
357 if ( !m_node1
.isNull() ){
358 ret
= m_node1
.nodeValue() + ' ';
361 if ( !m_node2
.isNull() ){
362 ret
+= m_node2
.nodeValue();
367 QString
Author::getRawData() const
369 QString ret
= QString();
370 if ( !m_node1
.isNull() ){
371 ret
= m_node1
.nodeValue() + ' ';
374 if ( !m_node2
.isNull() ){
375 ret
+= m_node2
.nodeValue();
380 void Author::setData(const QString
&data
, QDomDocument
&)
383 QString m_data
= data
;
384 m_data
.replace( QRegExp("\n"), "" ); // remove Newlines
385 m_data
.replace( QRegExp(" {2,}"), " " ); // remove multiple spaces
386 m_data
.replace( QRegExp("[\t|\r]{1,}"), ""); // remove Tabs
387 // split string "firstname surname"
388 QString firstname
= m_data
.section(' ', 0, 0);
389 QString surname
= m_data
.section(' ', 1, 1);
390 // update node elements
391 m_node1
.setNodeValue(firstname
);
392 m_node2
.setNodeValue(surname
);
394 this->setText(1, firstname
+ ' ' + surname
);
401 KeywordSet::KeywordSet(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
402 : ListViewInterface(parent
, after
, label
)
404 QPixmap pixmap
= KIconLoader::global()->loadIcon("txt", K3Icon::Small
);
405 this->setPixmap(0, pixmap
);
406 this->setText(3, "00000004");
407 m_iseditable
= false;
410 KeywordSet::~KeywordSet()
414 QString
KeywordSet::getRTFHeader() const
416 QString header
= "<H2>" + this->text(0) + "</H2>";
420 QString
KeywordSet::getHeader() const
422 QString header
= this->text(0) + '\n';
430 Keyword::Keyword(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
431 : ListViewInterface(parent
, after
, label
)
434 m_iseditable
= false;
441 void Keyword::setNodes( const NodeList_type
&list
)
444 m_node
= list
.front();
447 void Keyword::getNodes( NodeList_type
&list
) const
449 list
.push_back( m_node
);
452 QString
Keyword::getRTFData() const
454 if ( !m_node
.isNull() ){
455 QString keyword
= m_node
.nodeValue() + "<br>";
461 QString
Keyword::getData() const
463 if ( !m_node
.isNull() ){
464 return m_node
.nodeValue();
469 QString
Keyword::getRawData() const
473 // get content of element
474 QTextStream
in(&ret
, QIODevice::WriteOnly
);
475 in
.setEncoding(QTextStream::UnicodeUTF8
);
481 void Keyword::setData(const QString
&data
, QDomDocument
&)
483 m_node
.setNodeValue(data
);
484 this->setText(0, data
); // update ListView
491 Abstract::Abstract(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
492 : ListViewInterface(parent
, after
, label
)
494 QPixmap pixmap
= KIconLoader::global()->loadIcon("document-new", K3Icon::Small
);
495 this->setPixmap(0, pixmap
);
496 this->setText(3, "00000005");
497 m_iseditable
= false;
500 Abstract::~Abstract()
504 QString
Abstract::getRTFHeader() const
506 QString header
= "<H2>" + this->text(0) + "</H2>";
510 QString
Abstract::getHeader() const
512 QString header
= this->text(0) + '\n';
520 Para::Para(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
521 : ListViewInterface(parent
, after
, label
)
523 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
524 this->setPixmap(0, pixmap
);
526 m_iseditable
= false;
533 void Para::setNodes( const NodeList_type
&list
)
536 m_node
= list
.front();
539 void Para::getNodes( NodeList_type
&list
) const
541 list
.push_back( m_node
);
544 QString
Para::getRTFHeader() const
549 QString
Para::getHeader() const
551 QString header
= this->text(0) + '\n';
555 QString
Para::getRTFData() const
557 // get content of element
559 QTextStream
in(¶graph
, QIODevice::WriteOnly
);
560 in
.setEncoding(QTextStream::UnicodeUTF8
);
563 // delegate job to SAX-Parser
567 ParaSaxParser
*p
= ParaSaxParser::Instance();
568 p
->setData( paragraph
);
569 p
->getRTFText( data
);
570 ret
= "<p>" + data
+ "</p>";
575 QString
Para::getData() const
577 // get content of element
579 QTextStream
in(¶graph
, QIODevice::WriteOnly
);
580 in
.setEncoding(QTextStream::UnicodeUTF8
);
583 // delegate job to SAX-Parser
586 ParaSaxParser
*p
= ParaSaxParser::Instance();
587 p
->setData( paragraph
);
593 QString
Para::getRawData() const
597 // get content of element
598 QTextStream
in(&ret
, QIODevice::WriteOnly
);
599 in
.setEncoding(QTextStream::UnicodeUTF8
);
601 // remove opening and closing para-tags
602 ret
.replace( QRegExp("</?(para|Para|PARA)/?>"),"");
603 ret
.replace( QRegExp("^ "),"" );
604 ret
.replace( QRegExp("^\n"), "" );
609 void Para::setData(const QString
&data
, QDomDocument
&)
611 kDebug(100200) << "Para::setData()" << endl
;
614 QString l_data
= "<para>\n" + data
+ "\n</para>";
616 // create a temporary document
618 QDomDocument tempDoc
;
619 if ( !tempDoc
.setContent(l_data
) ){
620 l_data
= "<para><![CDATA[\n" + data
+ "\n]]></para>";
622 if ( !tempDoc
.setContent(l_data
) ){
623 err
= i18n("Unable to make document persistent.");
624 kDebug() << err
<< endl
;
628 err
= i18n("This paragraph contains mismatching tags. It will will be handled as CDATA.");
629 KMessageBox::information(0, err
, i18n("XML-Error"));
633 QDomNode parent
= m_node
.parentNode();
634 if ( parent
.isNull() ){
635 kDebug(100200) << "Para::setData(): Structural DocBook format error." << endl
;
640 parent
.replaceChild(tempDoc
, m_node
);
648 Chapter::Chapter(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
649 : ListViewInterface(parent
, after
, label
)
651 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
652 this->setPixmap(0, pixmap
);
653 m_iseditable
= false;
660 QString
Chapter::getRTFHeader() const
662 QString header
= "<H1>" + this->text(0) + "</H1>";
666 QString
Chapter::getHeader() const
668 QString header
= this->text(0) + '\n';
676 Sect1::Sect1(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
677 : ListViewInterface(parent
, after
, label
)
679 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
680 this->setPixmap(0, pixmap
);
681 m_iseditable
= false;
688 QString
Sect1::getRTFHeader() const
690 QString header
= "<H2>" + this->text(0) + "</H2>";
694 QString
Sect1::getHeader() const
696 QString header
= this->text(0) + '\n';
704 Sect2::Sect2(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
705 : ListViewInterface(parent
, after
, label
)
707 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
708 this->setPixmap(0, pixmap
);
709 m_iseditable
= false;
716 QString
Sect2::getRTFHeader() const
718 QString header
= "<H3>" + this->text(0) + "</H3>";
722 QString
Sect2::getHeader() const
724 QString header
= this->text(0) + '\n';
732 Sect3::Sect3(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
733 : ListViewInterface(parent
, after
, label
)
735 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
736 this->setPixmap(0, pixmap
);
737 m_iseditable
= false;
744 QString
Sect3::getRTFHeader() const
746 QString header
= "<B>" + this->text(0) + "</B><br>";
750 QString
Sect3::getHeader() const
752 QString header
= this->text(0) + '\n';
760 Sect4::Sect4(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
761 : ListViewInterface(parent
, after
, label
)
763 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
764 this->setPixmap(0, pixmap
);
765 m_iseditable
= false;
772 QString
Sect4::getRTFHeader() const
774 QString header
= "<B>" + this->text(0) + "</B><br>";
778 QString
Sect4::getHeader() const
780 QString header
= this->text(0) + '\n';
788 Sect5::Sect5(ListViewInterface
*parent
, ListViewInterface
*after
, QString label
)
789 : ListViewInterface(parent
, after
, label
)
791 QPixmap pixmap
= KIconLoader::global()->loadIcon("leftjust", K3Icon::Small
);
792 this->setPixmap(0, pixmap
);
793 m_iseditable
= false;
800 QString
Sect5::getRTFHeader() const
802 QString header
= "<B>" + this->text(0) + "</B><br>";
806 QString
Sect5::getHeader() const
808 QString header
= this->text(0) + '\n';