2 KNode, the KDE newsreader
3 Copyright (c) 1999-2006 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
18 #include <k3listview.h>
20 #include <kxmlguiwindow.h>
24 #include <QCloseEvent>
30 #include <QContextMenuEvent>
32 #include <QDragEnterEvent>
36 #include <kabc/addresslineedit.h>
51 namespace KPIMUtils
{ class SpellingFilter
; }
52 using KPIMUtils::SpellingFilter
;
54 /** Message composer window. */
55 class KNComposer
: public KXmlGuiWindow
{
58 Q_CLASSINFO( "D-Bus Interface", "org.kde.knode.composer")
61 enum composerResult
{ CRsendNow
, CRsendLater
, CRdelAsk
,
62 CRdel
, CRsave
, CRcancel
};
63 enum MessageMode
{ news
=0, mail
=1, news_mail
=2 };
65 // unwraped == original, not rewraped text
66 // firstEdit==true: place the cursor at the end of the article
67 // allowMail==false: Sending using smtp is disabled
68 KNComposer( KNLocalArticle
*a
, const QString
&text
= QString(), const QString
&sig
= QString(),
69 const QString
&unwraped
= QString(), bool firstEdit
= false,
70 bool dislikesCopies
= false, bool createCopy
= false, bool allowMail
= true);
72 void setConfig(bool onlyFonts
);
73 void setMessageMode(MessageMode mode
);
77 composerResult
result() const { return r_esult
; }
78 KNLocalArticle
* article()const { return a_rticle
; }
81 void closeEvent(QCloseEvent
*e
);
84 //set data from the given article
85 Q_SCRIPTABLE
void initData(const QString
&text
);
89 /** Inserts at cursor position if clear is false, replaces content otherwise
90 * puts the file content into a box if box==true
91 * "file" is already open for reading
93 void insertFile( QFile
*file
, bool clear
= false, bool box
= false, const QString
&boxTitle
= QString() );
95 /// ask for a filename, handle network urls
96 void insertFile(bool clear
=false, bool box
=false);
98 QMenu
* popupMenu( const QString
& name
);
99 int listOfResultOfCheckWord( const QStringList
& lst
, const QString
& selectWord
);
104 class AttachmentView
;
105 class AttachmentViewItem
;
106 class AttachmentPropertiesDlg
;
113 composerResult r_esult
;
114 KNLocalArticle
*a_rticle
;
115 QString s_ignature
, u_nwraped
;
117 bool n_eeds8Bit
, // false: fall back to us-ascii
118 v_alidated
, // hasValidData was run and found no problems, n_eeds8Bit is valid
119 a_uthorDislikesMailCopies
;
122 Sets the character set to used to encode this message.
123 This also enforces some sanity check.
125 void setCharset( const QString
&charset
);
128 bool e_xternalEdited
;
129 KProcess
*e_xternalEditor
;
130 KTemporaryFile
*e_ditorTempfile
;
131 SpellingFilter
* mSpellingFilter
;
134 QList
<KNAttachment
*> mDeletedAttachments
;
135 QList
<QAction
*> m_listAction
;
138 //------------------------------ <Actions> -----------------------------
140 QAction
*a_ctExternalEditor
,
142 *a_ctRemoveAttachment
,
143 *a_ctAttachmentProperties
,
145 KToggleAction
*a_ctPGPsign
,
146 *a_ctDoPost
, *a_ctDoMail
, *a_ctWordWrap
, *a_ctAutoSpellChecking
;
147 KSelectAction
*a_ctSetCharset
;
151 void slotSendLater();
152 void slotSaveAsDraft();
153 void slotArtDelete();
154 void slotAppendSig();
155 void slotInsertFile();
156 void slotInsertFileBoxed();
157 void slotAttachFile();
158 void slotRemoveAttachment();
159 void slotAttachmentProperties();
160 void slotToggleDoPost();
161 void slotToggleDoMail();
162 void slotSetCharset(const QString
&s
);
163 void slotSetCharsetKeyboard();
164 void slotToggleWordWrap();
165 void slotAutoSpellCheckingToggled();
166 void slotUndoRewrap();
167 void slotExternalEditor();
169 void slotUpdateStatusBar();
170 void slotUpdateCursorPos();
172 void slotConfToolbar();
173 void slotNewToolbarConfig();
174 void slotUpdateCheckSpellChecking(bool _b
);
176 //------------------------------ </Actions> ----------------------------
179 void slotSubjectChanged(const QString
&t
);
180 void slotGroupsChanged(const QString
&t
);
181 void slotToBtnClicked();
182 void slotGroupsBtnClicked();
185 void slotEditorFinished(int, QProcess::ExitStatus
);
186 void slotCancelEditor();
189 void slotAttachmentPopup(K3ListView
*, Q3ListViewItem
*it
, const QPoint
&p
);
190 void slotAttachmentSelected(Q3ListViewItem
*it
);
191 void slotAttachmentEdit(Q3ListViewItem
*it
);
192 void slotAttachmentRemove(Q3ListViewItem
*it
);
194 // spellcheck operation
195 //void slotSpellStarted(K3Spell *);
196 //void slotSpellDone(const QString&);
197 //void slotSpellFinished();
200 virtual void slotDragEnterEvent(QDragEnterEvent
*);
201 virtual void slotDropEvent(QDropEvent
*);
208 void slotSelectAll();
209 void addRecentAddress();
214 virtual void dragEnterEvent(QDragEnterEvent
*);
215 virtual void dropEvent(QDropEvent
*);
218 void composerDone(KNComposer
*);
223 Character set used to encode the out-going message.
225 This is going to end in the mime header of the message
226 so it should be a valid encoding as per
227 @link http://www.iana.org/assignments/character-sets IANA character-set encoding @endlink
228 and not be empty; both issue are taken care of by setCharset().
230 As a consequence this can not used directly as input of methods from KCharset.
236 /** Message Compser editor, handles tabs (expanding them in textLine(), etc.) */
237 class KNComposer::Editor
: public KEdit
{
242 Editor( KNComposer::ComposerView
*_composerView
, KNComposer
*_composer
, QWidget
*parent
= 0 );
244 QStringList
processedText();
247 void slotPasteAsQuotation();
249 void slotSearchAgain();
251 void slotAddQuotes();
252 void slotRemoveQuotes();
254 void slotRemoveBox();
256 void slotCorrectWord();
259 void slotSpellStarted( K3Spell
*);
260 void slotSpellDone(const QString
&);
261 void slotSpellFinished();
263 virtual void clear();
266 void sigDragEnterEvent(QDragEnterEvent
*);
267 void sigDropEvent(QDropEvent
*);
272 virtual void contentsDragEnterEvent(QDragEnterEvent
*);
273 virtual void contentsDropEvent(QDropEvent
*);
274 virtual void contentsContextMenuEvent( QContextMenuEvent
*e
);
275 virtual void keyPressEvent ( QKeyEvent
*e
);
277 virtual bool eventFilter(QObject
*, QEvent
*);
279 KNComposer
*m_composer
;
280 KNComposer::ComposerView
*m_composerView
;
282 QMap
<QString
,QStringList
> m_replacements
;
287 /** Attachment view of the message composer. */
288 class KNComposer::AttachmentView
: public K3ListView
{
293 AttachmentView( QWidget
*parent
);
297 void keyPressEvent( QKeyEvent
*e
);
300 void delPressed ( Q3ListViewItem
* ); // the user used Key_Delete on a list view item
304 /** Attachment view item. */
305 class KNComposer::AttachmentViewItem
: public K3ListViewItem
{
308 AttachmentViewItem(K3ListView
*v
, KNAttachment
*a
);
309 ~AttachmentViewItem();
311 KNAttachment
*attachment
;
316 /** Attachment properties dialog. */
317 class KNComposer::AttachmentPropertiesDlg
: public KDialog
{
322 AttachmentPropertiesDlg( KNAttachment
*a
, QWidget
*parent
= 0 );
323 ~AttachmentPropertiesDlg();
328 KLineEdit
*m_imeType
,
330 QComboBox
*e_ncoding
;
332 KNAttachment
*a_ttachment
;
337 void slotMimeTypeTextChanged(const QString
&text
);
340 //-----------------------------------------------------------------------------
341 /** Line edit for addresses used in the composer. */
342 class KNLineEdit
: public KABC::AddressLineEdit
345 typedef KABC::AddressLineEdit KNLineEditInherited
;
348 KNLineEdit( KNComposer::ComposerView
*_composerView
, bool useCompletion
, QWidget
*parent
= 0 );
350 // Inherited. Always called by the parent when this widget is created.
351 virtual void loadAddresses();
352 void keyPressEvent(QKeyEvent
*e
);
353 virtual void contextMenuEvent( QContextMenuEvent
*e
);
355 void editRecentAddresses();
357 KNComposer::ComposerView
*composerView
;
360 /** Line edit with on-the-fly spell checking. */
361 class KNLineEditSpell
: public KNLineEdit
365 KNLineEditSpell( KNComposer::ComposerView
*_composerView
, bool useCompletion
, QWidget
* parent
);
366 void highLightWord( unsigned int length
, unsigned int pos
);
367 void spellCheckDone( const QString
&s
);
368 void spellCheckerMisspelling( const QString
&text
, const QStringList
&, unsigned int pos
);
369 void spellCheckerCorrected( const QString
&old
, const QString
&corr
, unsigned int pos
);