SVN_SILENT made messages (.desktop file)
[kdepim.git] / knode / kncomposer.h
blob652b29e61c0e45d62e429ebac3460c6348161aa4
1 /*
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
15 #ifndef KNCOMPOSER_H
16 #define KNCOMPOSER_H
18 #include "knarticle.h"
20 #include <kxmlguiwindow.h>
21 #include <kdialog.h>
22 #include <QList>
23 #include <kprocess.h>
24 #include <kabc/addresslineedit.h>
27 class KSelectAction;
28 class KTemporaryFile;
29 class KToggleAction;
30 class QComboBox;
31 class QFile;
32 namespace KNode {
33 namespace Composer {
34 class View;
37 using KNode::Composer::View;
40 /** Message composer window. */
41 class KNComposer : public KXmlGuiWindow {
43 Q_OBJECT
44 Q_CLASSINFO( "D-Bus Interface", "org.kde.knode.composer")
46 public:
47 enum composerResult { CRsendNow, CRsendLater, CRdelAsk,
48 CRdel, CRsave, CRcancel };
50 enum MessageMode {
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.
56 /**
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);
70 ~KNComposer();
71 void setConfig(bool onlyFonts);
72 void setMessageMode(MessageMode mode);
74 //get result
75 bool hasValidData();
76 composerResult result() const { return r_esult; }
77 KNLocalArticle::Ptr article() const { return a_rticle; }
79 /**
80 Applies changes from the editor into the article being edited.
81 @return false if an error occurred.
83 bool applyChanges();
85 void closeEvent(QCloseEvent *e);
87 public slots:
88 //set data from the given article
89 Q_SCRIPTABLE void initData(const QString &text);
91 public:
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);
102 //internal classes
103 class Editor;
104 class AttachmentPropertiesDlg;
106 //GUI
107 View *v_iew;
109 //Data
110 composerResult r_esult;
111 KNLocalArticle::Ptr a_rticle;
112 QString u_nwraped;
113 MessageMode m_ode;
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 );
124 //edit
125 bool e_xternalEdited;
126 KProcess *e_xternalEditor;
127 KTemporaryFile *e_ditorTempfile;
129 //Attachments
130 QList<KNAttachment::Ptr> mDeletedAttachments;
131 bool a_ttChanged;
133 //------------------------------ <Actions> -----------------------------
135 QAction *a_ctExternalEditor,
136 *a_ctSpellCheck,
137 *a_ctRemoveAttachment,
138 *a_ctAttachmentProperties,
139 *a_ctSetCharsetKeyb;
140 KToggleAction *a_ctPGPsign,
141 *a_ctDoPost, *a_ctDoMail, *a_ctWordWrap, *a_ctAutoSpellChecking;
142 KSelectAction *a_ctSetCharset;
143 protected slots:
144 void slotSendNow();
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();
162 void slotConfKeys();
163 void slotConfToolbar();
164 void slotNewToolbarConfig();
165 void slotUpdateCheckSpellChecking(bool _b);
167 //------------------------------ </Actions> ----------------------------
169 // GUI
170 void slotSubjectChanged(const QString &t);
171 void slotToBtnClicked();
172 void slotGroupsBtnClicked();
174 // external editor
175 void slotEditorFinished(int, QProcess::ExitStatus);
176 void slotCancelEditor();
178 // attachment list
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();
194 void slotUndo();
195 void slotRedo();
196 void slotCut();
197 void slotCopy();
198 void slotPaste();
199 void slotSelectAll();
200 void addRecentAddress();
202 protected:
204 // DND handling
206 Reimplemented 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 );
214 signals:
215 void composerDone(KNComposer*);
217 private:
218 bool mFirstEdit;
220 Character set used to encode the out-going message.
222 This is going to end up 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 issues are taken care of by setCharset().
227 As a consequence this cannot be used directly as input of methods from KCharset.
229 QString mCharset;
233 /** Attachment properties dialog. */
234 class KNComposer::AttachmentPropertiesDlg : public KDialog {
236 Q_OBJECT
238 public:
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 );
248 Destructor.
250 ~AttachmentPropertiesDlg();
252 protected:
254 Apply the change to the attachment passed to the constructor.
256 void apply();
258 KLineEdit *m_imeType,
259 *d_escription;
260 QComboBox *e_ncoding;
262 KNAttachment::Ptr a_ttachment;
263 bool n_onTextAsText;
265 protected slots:
266 void accept();
267 void slotMimeTypeTextChanged(const QString &text);
270 //-----------------------------------------------------------------------------
271 /** Line edit for addresses used in the composer. */
272 class KNLineEdit : public KABC::AddressLineEdit
274 Q_OBJECT
276 public:
278 Constructor.
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; }
293 protected:
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 );
298 private slots:
299 void editRecentAddresses();
300 private:
301 View *composerView;
304 /** Line edit with on-the-fly spell checking. */
305 class KNLineEditSpell : public KNLineEdit
307 Q_OBJECT
308 public:
310 Constructor.
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);
325 #endif