2 KNode, the KDE newsreader
3 Copyright (c) 2005 Volker Krause <vkrause@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 You should have received a copy of the GNU General Public License
10 along with this program; if not, write to the Free Software Foundation,
11 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
14 #ifndef KNODE_ARTICLEWIDGET_H
15 #define KNODE_ARTICLEWIDGET_H
17 #include "knarticle.h"
18 #include "knarticlecollection.h"
19 #include "knjobdata.h"
25 #include <kmime/kmime_content.h>
29 class KActionCollection
;
45 Widget to display a news article.
47 class ArticleWidget
: public QWidget
, public KNJobConsumer
{
52 /// Construct a new article widget.
53 ArticleWidget( QWidget
*parent
,
54 KXMLGUIClient
*guiClient
,
55 KActionCollection
*actionCollection
, bool isMainViewer
= false );
56 /// Destroy the article widget.
59 /// read config settings
61 /// write config settings (call only for the main viewer)
64 /** display the given article
65 * @param article The article to display.
67 void setArticle( KNArticle::Ptr article
);
68 /// returns the currently shown article
69 KNArticle::Ptr
article() const { return mArticle
; }
71 /// notify all instances about a config change
72 static void configChanged();
73 /** check whether the given article is displayed in any instance
74 * @param article The article to check.
76 static bool articleVisible( KNArticle::Ptr article
);
77 /** notify all instances that the given article has been removed
78 * @param article The removed article.
80 static void articleRemoved( KNArticle::Ptr article
);
81 /** notify all instances that the given article has changed
82 * @param article The changed article.
84 static void articleChanged( KNArticle::Ptr article
);
85 /** notify all instances about an error during loading the given article
86 * @param article The article that couldn't be loaded.
87 * @param error The error message.
89 static void articleLoadError( KNArticle::Ptr article
, const QString
&error
);
90 /** notify all instances that the given collection has been removed
91 * @param coll The removed article collection (a group or a folder).
93 static void collectionRemoved( KNArticleCollection::Ptr coll
);
94 /// cleanup all instances
95 static void cleanup();
97 /// checks whether the readers is scrolled down to the bottom
98 bool atBottom() const;
101 /// scroll up by one line
103 /// scroll down by one line
105 /// scroll up by one page
107 /// scroll down by one page
111 /// process download jobs for view source action
112 void processJob( KNJobData
*j
);
117 /// enable article dependent actions
118 void enableActions();
119 /// disable article dependent actions
120 void disableActions();
122 /// clears the article viewer
124 /// displays the current article or clears the view if no article is set
125 void displayArticle();
126 /// displays the given error message in the viewer
127 void displayErrorMessage( const QString
&msg
);
129 /// display the message header (should be replaced by KMail's HeaderStyle class)
130 void displayHeader();
131 /** displays the given text block, including quote and signature handling
132 * @param lines A list of lines to display.
134 void displayBodyBlock( const QStringList
&lines
);
135 /// displays a signature block header
136 QString
displaySigHeader( const Kpgp::Block
&block
);
137 /// displays a signature footer
138 void displaySigFooter( const QString
&signClass
);
139 /// displays the given attachment
140 void displayAttachment( KMime::Content
*att
, int partNum
);
142 /// HTML conversion flags for toHtmlString()
143 enum ConversionFlags
{
149 /// convert the given string into a HTML string
150 QString
toHtmlString( const QString
&line
, int flags
= ParseURL
);
151 /// convert the given image into a data:/ URL
152 static QString
imgToDataUrl( const QImage
&image
, const char* fmt
);
154 /** calculates the quoting depth of the given line
155 * @returns -1 if no quoting was found, the quoting level otherwise
157 static int quotingDepth( const QString
&line
, const QString
"eChars
);
158 /// checks whether the given attachment can be shown inline
159 bool inlinePossible( KMime::Content
*c
);
160 /** Checks if the given charset is supported.
161 * @param charset The charset to check.
163 bool canDecodeText( const QByteArray
&charset
) const;
165 /// regenerated viewer content without changing scrollbar position
166 void updateContents();
168 /** stores the given attachment into a temporary file
169 * @returns an URL which reprensents the filename the attachment has been stored to
171 KUrl
writeAttachmentToTempFile( KMime::Content
*att
, int partNum
);
172 /// removes all temporary files
173 void removeTempFiles();
176 /// called if the user clicked on an URL
177 void slotURLClicked( const KUrl
&url
, bool forceOpen
= false );
178 /// called if the user RMB clicked on an URL
179 void slotURLPopup( const QString
&url
, const QPoint
&point
);
181 /// mark as read timeout
186 void slotCopySelection();
187 void slotSelectAll();
189 void slotViewSource();
194 void slotSupersede();
195 void slotToggleFixedFont();
196 void slotToggleFancyFormating();
197 void slotToggleRot13();
199 void slotFancyHeaders();
200 void slotStandardHeaders();
201 void slotAllHeaders();
203 void slotIconAttachments();
204 void slotInlineAttachments();
205 void slotHideAttachments();
207 void slotSetCharset( const QString
&charset
);
208 void slotSetCharsetKeyboard();
212 void slotAddBookmark();
213 void slotAddToAddressBook();
214 void slotOpenInAddressBook();
215 void slotOpenAttachment();
216 void slotSaveAttachment();
219 /// the currently shown article
220 KNArticle::Ptr mArticle
;
221 /// attachments of the current article
222 KMime::Content::List mAttachments
;
223 /// mapping of temporary file names to part numbers
224 QMap
<QString
, int> mAttachementMap
;
227 CSSHelper
*mCSSHelper
;
229 QStringList mTempDirs
, mTempFiles
;
231 QString mHeaderStyle
;
232 QString mAttachmentStyle
;
236 QByteArray mOverrideCharset
;
238 /// mark as read timer
241 /// the last RMB clicked URL
244 /// list of all instances of this class
245 static QList
<ArticleWidget
*> mInstances
;
247 Indicates if this ArticleWidget is the main one (displayed in KNMainWidget)
251 KXMLGUIClient
*mGuiClient
;
252 KActionCollection
*mActionCollection
;
254 QAction
*mSaveAction
;
255 QAction
*mPrintAction
;
256 QAction
*mCopySelectionAction
;
257 QAction
*mSelectAllAction
;
258 QAction
*mFindAction
;
259 KAction
*mViewSourceAction
;
260 KAction
*mCharsetSelectKeyb
;
261 KAction
*mReplyAction
;
262 KAction
*mRemailAction
;
263 KAction
*mForwardAction
;
264 KAction
*mCancelAction
;
265 KAction
*mSupersedeAction
;
266 KActionMenu
*mHeaderStyleMenu
;
267 KActionMenu
*mAttachmentStyleMenu
;
268 KToggleAction
*mFixedFontToggle
;
269 KToggleAction
*mFancyToggle
;
270 KToggleAction
*mRot13Toggle
;
271 KSelectAction
*mCharsetSelect
;