Framework for looking up contacts directly in nepomuk in addition to going through...
[kdepim.git] / messageviewer / mailsourceviewer.h
blobbb7363f8b76b82d145d7c78f5fc16a9f0f614872
1 /* -*- mode: C++; c-file-style: "gnu" -*-
3 * This file is part of KMail, the KDE mail client.
5 * Copyright (c) 2002-2003 Carsten Pfeiffer <pfeiffer@kde.org>
6 * Copyright (c) 2003 Zack Rusin <zack@kde.org>
8 * KMail is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License, version 2, as
10 * published by the Free Software Foundation.
12 * KMail is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * In addition, as a special exception, the copyright holders give
22 * permission to link the code of this program with any edition of
23 * the Qt library by Trolltech AS, Norway (or with modified versions
24 * of Qt that use the same license as Qt), and distribute linked
25 * combinations including the two. You must obey the GNU General
26 * Public License in all respects for all of the code used other than
27 * Qt. If you modify this file, you may extend this exception to
28 * your version of the file, but you are not obligated to do so. If
29 * you do not wish to do so, delete this exception statement from
30 * your version.
32 #ifndef MAILSOURCEVIEWER_H
33 #define MAILSOURCEVIEWER_H
35 #include <QSyntaxHighlighter>
36 #include <KTabWidget>
37 #include <QPlainTextEdit>
38 #include <KDialog>
39 class QString;
40 class QWidget;
41 class QShowEvent;
43 namespace MessageViewer {
44 class FindBarSourceView;
46 /**
47 * A tiny little class to use for displaying raw messages, textual
48 * attachments etc.
50 * Auto-deletes itself when closed.
52 * @author Carsten Pfeiffer <pfeiffer@kde.org>
54 class MailSourceViewTextBrowser;
55 class MailSourceHighlighter : public QSyntaxHighlighter
57 public:
58 MailSourceHighlighter( QTextDocument * textdocument )
59 : QSyntaxHighlighter( textdocument )
61 protected:
62 virtual void highlightBlock ( const QString & text );
65 class HTMLSourceHighlighter : public QSyntaxHighlighter
67 public:
68 HTMLSourceHighlighter( QTextDocument * textdocument )
69 : QSyntaxHighlighter( textdocument )
71 protected:
72 virtual void highlightBlock ( const QString & text );
75 class MailSourceViewTextBrowserWidget : public QWidget
77 Q_OBJECT
78 public:
79 explicit MailSourceViewTextBrowserWidget( QWidget *parent = 0 );
81 void setText( const QString& text );
82 void setPlainText( const QString& text );
83 MessageViewer::MailSourceViewTextBrowser *textBrowser() const;
84 private slots:
85 void slotFind();
86 private:
87 MailSourceViewTextBrowser *mTextBrowser;
88 FindBarSourceView *mFindBar;
91 class MailSourceViewTextBrowser: public QPlainTextEdit
93 Q_OBJECT
94 public:
95 explicit MailSourceViewTextBrowser( QWidget *parent = 0 );
96 protected:
97 virtual void contextMenuEvent( QContextMenuEvent *event );
98 private slots:
99 void slotSpeakText();
100 signals:
101 void findText();
104 namespace HTMLPrettyFormatter
106 // Best to be really verbose about this one...
107 const QRegExp htmlTagRegExp( "<"
108 "(/)?" //Captures the / if this is an end tag.
109 "(\\w+)" //Captures TagName
110 "(?:" //Groups tag contents
111 "(?:\\s+" //Groups attributes
112 "(?:\\w+)" //Attribute name
113 "(?:" //groups =value portion.
114 "\\s*=\\s*" // =
115 "(?:" //Groups attribute "value" portion.
116 "\\\"(?:[^\\\"]*)\\\"" // attVal='double quoted'
117 "|'(?:[^']*)'" // attVal='single quoted'
118 "|(?:[^'"">\\s]+)" // attVal=urlnospaces
120 ")?" //end optional att value portion.
121 ")+\\s*" //One or more attribute pairs
122 "|\\s*" //Some white space.
124 "(/)?>" //Captures the "/" if this is a complete tag.
127 const QString reformat( const QString &src );
130 class MailSourceViewer : public KDialog
132 Q_OBJECT
133 public:
134 MailSourceViewer( QWidget *parent = 0 );
135 ~MailSourceViewer();
137 void setRawSource( const QString &source );
138 void setDisplayedSource( const QString &source );
139 private:
140 KTabWidget *mTabWidget;
141 MailSourceViewTextBrowserWidget *mRawBrowser;
142 FindBarSourceView *mFindBar;
143 #ifndef NDEBUG
144 MailSourceViewTextBrowserWidget *mHtmlBrowser;
145 HTMLSourceHighlighter *mHtmlSourceHighLighter;
146 #endif
147 MailSourceHighlighter *mRawSourceHighLighter;
151 #endif // MAILSOURCEVIEWER_H