summaryrefslogtreecommitdiffstats
path: root/knode/articlewidget.h
blob: 8a00e33fe04645489119875ac02b33bce5bdf662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
    KNode, the KDE newsreader
    Copyright (c) 2005 Volker Krause <volker.krause@rwth-aachen.de>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
*/

#ifndef KNODE_ARTICLEWIDGET_H
#define KNODE_ARTICLEWIDGET_H

#include <tqmap.h>
#include <tqvaluelist.h>
#include <tqwidget.h>

#include <kurl.h>

#include <kmime_content.h>

#include "knjobdata.h"

class TQStringList;
class TQTimer;

class TDEAction;
class TDEActionCollection;
class TDEActionMenu;
class TDEHTMLPart;
class KURL;
class TDESelectAction;
class TDEToggleAction;
class KXMLGUIClient;

namespace Kpgp {
  class Block;
}

class KNArticle;
class KNArticleCollection;

namespace KNode {

class CSSHelper;

/**
  Widget to display a news article
*/
class ArticleWidget : public TQWidget, public KNJobConsumer {

  TQ_OBJECT
  

  public:
    /// Construct a new article widget
    ArticleWidget( TQWidget *parent,
                   KXMLGUIClient *guiClient,
                   TDEActionCollection *actionCollection,
                   const char *name = 0 );
    ~ArticleWidget();

    /// read config settings
    void readConfig();
    /// write config settings (call only for the main viewer)
    void writeConfig();

    /// display the given article
    void setArticle( KNArticle *article );
    /// returns the currently shown article
    KNArticle *article() const { return mArticle; }

    TDEAction* setCharsetKeyboardAction() const { return mCharsetSelectKeyb; }

    /// notify all instances about a config change
    static void configChanged();
    /// check wether the given article is displayed in any instance
    static bool articleVisible( KNArticle *article );
    /// notify all instances that the given article has been removed
    static void articleRemoved( KNArticle *article );
    /// notify all instances that the given article has changed
    static void articleChanged( KNArticle *article );
    /// notify all instances about an error during loading the given article
    static void articleLoadError( KNArticle *article, const TQString &error );
    /// notify all instances that the given collection has been removed
    static void collectionRemoved( KNArticleCollection *coll );
    /// cleanup all instances
    static void cleanup();

    /// checks wether the readers is scrolled down to the bottom
    bool atBottom() const;

  public slots:
    void scrollUp();
    void scrollDown();
    void scrollPrior();
    void scrollNext();

  signals:
    void focusChanged( TQFocusEvent* );
    void focusChangeRequest( TQWidget* );

  protected:
    /// process download jobs for view source action
    void processJob( KNJobData *j );

    virtual void focusInEvent( TQFocusEvent *e );
    virtual void focusOutEvent( TQFocusEvent *e );
    virtual bool eventFilter( TQObject *o, TQEvent *e );

  private:
    void initActions();

    /// enable article dependent actions
    void enableActions();
    /// disable article dependent actions
    void disableActions();

    /// clears the article viewer
    void clear();
    /// displays the current article or clears the view if no article is set
    void displayArticle();
    /// displays the given error message in the viewer
    void displayErrorMessage( const TQString &msg );

    /// display the message header (should be replaced by KMail's HeaderStyle class)
    void displayHeader();
    /** displays the given text block, including quote and signature handling
     *  @param lines A list of lines to display.
     */
    void displayBodyBlock( const TQStringList &lines );
    /// displays a signature block header
    TQString displaySigHeader( Kpgp::Block* block );
    /// displays a signature footer
    void displaySigFooter( const TQString &signClass );
    /// displays the given attachment
    void displayAttachment( KMime::Content *att, int partNum );

    /// HTML conversion flags for toHtmlString()
    enum ConversionFlags {
      None = 0,
      ParseURL = 1,
      FancyFormatting = 2,
      AllowROT13 = 4
    };
    /// convert the given string into an HTML string
    TQString toHtmlString( const TQString &line, int flags = ParseURL );
    /// convert the given image into a data:/ URL
    static TQString imgToDataUrl( const TQImage &image, const char* fmt );

    /** calculates the quoting depth of the given line
     *  @returns -1 if no quoting was found, the quoting level otherwise
     */
    static int quotingDepth( const TQString &line, const TQString &quoteChars );
    /// checks wether the given attachment can be shown inline
    bool inlinePossible( KMime::Content *c );
    /// checks if the given charset is supported
    bool canDecodeText( const TQCString &charset ) const;

    /// regenerated viewer content without changing scrollbar position
    void updateContents();

    /** stores the given attachment into a temporary file
     *  @returns the filename the attachment has been stored to
     */
    TQString writeAttachmentToTempFile( KMime::Content *att, int partNum );
    /// removes all temporary files
    void removeTempFiles();

  private slots:
    /// called if the user clicked on an URL
    void slotURLClicked( const KURL &url, bool forceOpen = false );
    /// called if the user RMB clicked on an URL
    void slotURLPopup( const TQString &url, const TQPoint &point );

    /// mark as read timeout
    void slotTimeout();

    void slotSave();
    void slotPrint();
    void slotCopySelection();
    void slotSelectAll();
    void slotFind();
    void slotViewSource();
    void slotReply();
    void slotRemail();
    void slotForward();
    void slotCancel();
    void slotSupersede();
    void slotToggleFixedFont();
    void slotToggleFancyFormating();
    void slotToggleRot13();

    void slotFancyHeaders();
    void slotStandardHeaders();
    void slotAllHeaders();

    void slotIconAttachments();
    void slotInlineAttachments();
    void slotHideAttachments();

    void slotSetCharset( const TQString &charset );
    void slotSetCharsetKeyboard();

    void slotOpenURL();
    void slotCopyURL();
    void slotAddBookmark();
    void slotAddToAddressBook();
    void slotOpenInAddressBook();
    void slotOpenAttachment();
    void slotSaveAttachment();

  private:
    /// the currently shown article
    KNArticle *mArticle;
    /// attachments of the current article
    KMime::Content::List mAttachments;
    /// mapping of temporary file names to part numbers
    TQMap<TQString, int> mAttachementMap;

    TDEHTMLPart *mViewer;
    CSSHelper *mCSSHelper;

    TQStringList mTempDirs, mTempFiles;

    TQString mHeaderStyle;
    TQString mAttachmentStyle;
    bool mShowHtml;
    bool mRot13;
    bool mForceCharset;
    TQCString mOverrideCharset;

    /// mark as read timer
    TQTimer *mTimer;

    /// the last RMB clicked URL
    KURL mCurrentURL;

    /// list of all instances of this class
    static TQValueList<ArticleWidget*> mInstances;

    KXMLGUIClient *mGuiClient;
    TDEActionCollection *mActionCollection;

    TDEAction *mSaveAction;
    TDEAction *mPrintAction;
    TDEAction *mCopySelectionAction;
    TDEAction *mSelectAllAction;
    TDEAction *mFindAction;
    TDEAction *mViewSourceAction;
    TDEAction *mCharsetSelectKeyb;
    TDEAction *mReplyAction;
    TDEAction *mRemailAction;
    TDEAction *mForwardAction;
    TDEAction *mCancelAction;
    TDEAction *mSupersedeAction;
    TDEActionMenu *mHeaderStyleMenu;
    TDEActionMenu *mAttachmentStyleMenu;
    TDEToggleAction *mFixedFontToggle;
    TDEToggleAction *mFancyToggle;
    TDEToggleAction *mRot13Toggle;
    TDESelectAction *mCharsetSelect;
};

}

#endif