Factor out the shared parts of the agent action manager setup.
[kdepim.git] / knode / articlewidget.h
blob93b6849ed493a84cb619b44c40abaf48b9f05a50
1 /*
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"
21 #include <QByteArray>
22 #include <QMap>
23 #include <QWidget>
24 #include <kurl.h>
25 #include <kmime/kmime_content.h>
27 class QTimer;
28 class KAction;
29 class KActionCollection;
30 class KActionMenu;
31 class KHTMLPart;
32 class KSelectAction;
33 class KToggleAction;
34 class KXMLGUIClient;
36 namespace Kpgp {
37 class Block;
40 namespace KNode {
42 class CSSHelper;
44 /**
45 Widget to display a news article.
47 class ArticleWidget : public QWidget, public KNJobConsumer {
49 Q_OBJECT
51 public:
52 /// Construct a new article widget.
53 ArticleWidget( QWidget *parent,
54 KXMLGUIClient *guiClient,
55 KActionCollection *actionCollection, bool isMainViewer = false );
56 /// Destroy the article widget.
57 ~ArticleWidget();
59 /// read config settings
60 void readConfig();
61 /// write config settings (call only for the main viewer)
62 void writeConfig();
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;
100 public slots:
101 /// scroll up by one line
102 void scrollUp();
103 /// scroll down by one line
104 void scrollDown();
105 /// scroll up by one page
106 void scrollPrior();
107 /// scroll down by one page
108 void scrollNext();
110 protected:
111 /// process download jobs for view source action
112 void processJob( KNJobData *j );
114 private:
115 void initActions();
117 /// enable article dependent actions
118 void enableActions();
119 /// disable article dependent actions
120 void disableActions();
122 /// clears the article viewer
123 void clear();
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 {
144 None = 0,
145 ParseURL = 1,
146 FancyFormatting = 2,
147 AllowROT13 = 4
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 &quoteChars );
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();
175 private slots:
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
182 void slotTimeout();
184 void slotSave();
185 void slotPrint();
186 void slotCopySelection();
187 void slotSelectAll();
188 void slotFind();
189 void slotViewSource();
190 void slotReply();
191 void slotRemail();
192 void slotForward();
193 void slotCancel();
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();
210 void slotOpenURL();
211 void slotCopyURL();
212 void slotAddBookmark();
213 void slotAddToAddressBook();
214 void slotOpenInAddressBook();
215 void slotOpenAttachment();
216 void slotSaveAttachment();
218 private:
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;
226 KHTMLPart *mViewer;
227 CSSHelper *mCSSHelper;
229 QStringList mTempDirs, mTempFiles;
231 QString mHeaderStyle;
232 QString mAttachmentStyle;
233 bool mShowHtml;
234 bool mRot13;
235 bool mForceCharset;
236 QByteArray mOverrideCharset;
238 /// mark as read timer
239 QTimer *mTimer;
241 /// the last RMB clicked URL
242 KUrl mCurrentURL;
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)
249 bool mIsMainViewer;
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;
276 #endif