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 "knarticle.h"
20 #include <kxmlguiwindow.h>
24 #include <kabc/addresslineedit.h>
37 using KNode::Composer::View
;
40 /** Message composer window. */
41 class KNComposer
: public KXmlGuiWindow
{
44 Q_CLASSINFO( "D-Bus Interface", "org.kde.knode.composer")
47 enum composerResult
{ CRsendNow
, CRsendLater
, CRdelAsk
,
48 CRdel
, CRsave
, CRcancel
};
51 news
= 0, ///< Message is to be sent to a newsgroup.
52 mail
= 1, ///< Message is to be sent by e-mail.
53 news_mail
= 2 ///< Message is to be sent by e-mail and to a newsgroup.
57 Create a composer for a message (e-mail or newsgroup post).
58 @param a The article to edit.
59 @param text The <strong>wraped</strong> text of the message.
60 @param unwraped The original, <strong>not rewraped</strong> text.
61 @param firstEdit Indicates if it is the first time that this message is edited.
62 @param dislikesCopies When true, this indicates that the author of the message
63 that is replied to did not want an e-mail copy of the answer.
64 @param createCopy When true, this indicates that a copy should be sent by e-mail.
65 @param allowMail Enables or disables sending the message via e-mail.
67 explicit KNComposer( KNLocalArticle::Ptr a
, const QString
&text
= QString(),
68 const QString
&unwraped
= QString(), bool firstEdit
= false,
69 bool dislikesCopies
= false, bool createCopy
= false, bool allowMail
= true);
71 void setConfig(bool onlyFonts
);
72 void setMessageMode(MessageMode mode
);
76 composerResult
result() const { return r_esult
; }
77 KNLocalArticle::Ptr
article() const { return a_rticle
; }
80 Applies changes from the editor into the article being edited.
81 @return false if an error occurred.
85 void closeEvent(QCloseEvent
*e
);
88 //set data from the given article
89 Q_SCRIPTABLE
void initData(const QString
&text
);
93 /** Inserts at cursor position if clear is false, replaces content otherwise
94 * puts the file content into a box if box==true
95 * "file" is already open for reading
97 void insertFile( QFile
*file
, bool clear
= false, bool box
= false, const QString
&boxTitle
= QString() );
99 /// ask for a filename, handle network urls
100 void insertFile(bool clear
=false, bool box
=false);
104 class AttachmentPropertiesDlg
;
110 composerResult r_esult
;
111 KNLocalArticle::Ptr a_rticle
;
114 bool n_eeds8Bit
, // false: fall back to us-ascii
115 v_alidated
, // hasValidData was run and found no problems, n_eeds8Bit is valid
116 a_uthorDislikesMailCopies
;
119 Sets the character set to used to encode this message.
120 This also enforces some sanity check.
122 void setCharset( const QString
&charset
);
125 bool e_xternalEdited
;
126 KProcess
*e_xternalEditor
;
127 KTemporaryFile
*e_ditorTempfile
;
130 QList
<KNAttachment::Ptr
> mDeletedAttachments
;
133 //------------------------------ <Actions> -----------------------------
135 QAction
*a_ctExternalEditor
,
137 *a_ctRemoveAttachment
,
138 *a_ctAttachmentProperties
,
140 KToggleAction
*a_ctPGPsign
,
141 *a_ctDoPost
, *a_ctDoMail
, *a_ctWordWrap
, *a_ctAutoSpellChecking
;
142 KSelectAction
*a_ctSetCharset
;
145 void slotSendLater();
146 void slotSaveAsDraft();
147 void slotArtDelete();
148 void slotInsertFile();
149 void slotInsertFileBoxed();
150 void slotAttachFile();
151 void slotToggleDoPost();
152 void slotToggleDoMail();
153 void slotSetCharset(const QString
&s
);
154 void slotSetCharsetKeyboard();
155 void slotToggleWordWrap();
156 void slotAutoSpellCheckingToggled();
157 void slotUndoRewrap();
158 void slotExternalEditor();
160 void slotUpdateStatusBar();
161 void slotUpdateCursorPos();
163 void slotConfToolbar();
164 void slotNewToolbarConfig();
165 void slotUpdateCheckSpellChecking(bool _b
);
167 //------------------------------ </Actions> ----------------------------
170 void slotSubjectChanged(const QString
&t
);
171 void slotToBtnClicked();
172 void slotGroupsBtnClicked();
175 void slotEditorFinished(int, QProcess::ExitStatus
);
176 void slotCancelEditor();
180 Open a popup menu to do action on an attachment
181 @param point the global position where the popup should be opened.
183 void slotAttachmentPopup( const QPoint
&point
);
185 Called by the View when an attachment was removed.
187 void slotAttachmentRemoved( KNAttachment::Ptr attachment
, bool last
);
189 Called by the View to notify that an attachment was modified.
191 void slotAttachmentChanged();
199 void slotSelectAll();
200 void addRecentAddress();
206 Reimplemted to accept list of URI as drag content
208 virtual void dragEnterEvent( QDragEnterEvent
*event
);
210 Reimplemented to add the dropped files as attachments.
212 virtual void dropEvent( QDropEvent
*event
);
215 void composerDone(KNComposer
*);
220 Character set used to encode the out-going message.
222 This is going to end in the mime header of the message
223 so it should be a valid encoding as per
224 @link http://www.iana.org/assignments/character-sets IANA character-set encoding @endlink
225 and not be empty; both issue are taken care of by setCharset().
227 As a consequence this can not used directly as input of methods from KCharset.
233 /** Attachment properties dialog. */
234 class KNComposer::AttachmentPropertiesDlg
: public KDialog
{
240 Create a dialog to edit attribute of a message attachment.
242 Note: if this dialog is accepted, the attachement @p a is updated automatically.
243 @param a The attachment to edit.
244 @param parent Parent widget.
246 AttachmentPropertiesDlg( KNAttachment::Ptr a
, QWidget
*parent
= 0 );
250 ~AttachmentPropertiesDlg();
254 Apply the change to the attachment passed to the constructor.
258 KLineEdit
*m_imeType
,
260 QComboBox
*e_ncoding
;
262 KNAttachment::Ptr a_ttachment
;
267 void slotMimeTypeTextChanged(const QString
&text
);
270 //-----------------------------------------------------------------------------
271 /** Line edit for addresses used in the composer. */
272 class KNLineEdit
: public KABC::AddressLineEdit
280 explicit KNLineEdit( View
*parent
, bool useCompletion
= true );
282 Helper constructor (for UI designer generated class).
283 You must call setView later.
285 explicit KNLineEdit( QWidget
*parent
, bool useCompletion
= true );
288 Sets the View that this line edit belongs to.
290 void setView( View
*view
)
291 { composerView
= view
; }
294 // Inherited. Always called by the parent when this widget is created.
295 virtual void loadAddresses();
296 void keyPressEvent(QKeyEvent
*e
);
297 virtual void contextMenuEvent( QContextMenuEvent
*e
);
299 void editRecentAddresses();
304 /** Line edit with on-the-fly spell checking. */
305 class KNLineEditSpell
: public KNLineEdit
312 explicit KNLineEditSpell( View
*parent
, bool useCompletion
= true );
314 Helper constructor (for UI designer generated class).
315 You must call setView later.
317 explicit KNLineEditSpell( QWidget
*parent
, bool useCompletion
= true );
319 void highLightWord( unsigned int length
, unsigned int pos
);
320 void spellCheckDone( const QString
&s
);
321 void spellCheckerMisspelling( const QString
&text
, const QStringList
&, unsigned int pos
);
322 void spellCheckerCorrected( const QString
&old
, const QString
&corr
, unsigned int pos
);