Fix typo found by Yuri Chornoivan
[kdepim.git] / knode / kncomposer.h
blobfd8c1dc1ab062f2102e73a0c0d8d5042ed1fae14
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 <k3listview.h>
20 #include <kxmlguiwindow.h>
21 #include <kdialog.h>
22 #include <QRegExp>
23 #include <QByteArray>
24 #include <QCloseEvent>
25 #include <QKeyEvent>
26 #include <QEvent>
27 #include <QDropEvent>
28 #include <QLabel>
29 #include <QList>
30 #include <QContextMenuEvent>
31 #include <QMenu>
32 #include <QDragEnterEvent>
33 #include <QSplitter>
35 #include <kprocess.h>
36 #include <kabc/addresslineedit.h>
38 class QGroupBox;
40 class KSelectAction;
41 class KToggleAction;
42 class KNLocalArticle;
43 class KNAttachment;
44 class KComboBox;
45 class QComboBox;
46 namespace KPIM {
47 class KMeditor;
49 using KPIM::KMeditor;
51 namespace KPIMUtils { class SpellingFilter; }
52 using KPIMUtils::SpellingFilter;
54 /** Message composer window. */
55 class KNComposer : public KXmlGuiWindow {
57 Q_OBJECT
58 Q_CLASSINFO( "D-Bus Interface", "org.kde.knode.composer")
60 public:
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);
71 ~KNComposer();
72 void setConfig(bool onlyFonts);
73 void setMessageMode(MessageMode mode);
75 //get result
76 bool hasValidData();
77 composerResult result() const { return r_esult; }
78 KNLocalArticle* article()const { return a_rticle; }
79 bool applyChanges();
81 void closeEvent(QCloseEvent *e);
83 public slots:
84 //set data from the given article
85 Q_SCRIPTABLE void initData(const QString &text);
87 public:
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);
101 //internal classes
102 class ComposerView;
103 class Editor;
104 class AttachmentView;
105 class AttachmentViewItem;
106 class AttachmentPropertiesDlg;
108 //GUI
109 ComposerView *v_iew;
110 QMenu *a_ttPopup;
112 //Data
113 composerResult r_esult;
114 KNLocalArticle *a_rticle;
115 QString s_ignature, u_nwraped;
116 MessageMode m_ode;
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 );
127 //edit
128 bool e_xternalEdited;
129 KProcess *e_xternalEditor;
130 KTemporaryFile *e_ditorTempfile;
131 SpellingFilter* mSpellingFilter;
133 //Attachments
134 QList<KNAttachment*> mDeletedAttachments;
135 QList<QAction*> m_listAction;
136 bool a_ttChanged;
138 //------------------------------ <Actions> -----------------------------
140 QAction *a_ctExternalEditor,
141 *a_ctSpellCheck,
142 *a_ctRemoveAttachment,
143 *a_ctAttachmentProperties,
144 *a_ctSetCharsetKeyb;
145 KToggleAction *a_ctPGPsign,
146 *a_ctDoPost, *a_ctDoMail, *a_ctWordWrap, *a_ctAutoSpellChecking;
147 KSelectAction *a_ctSetCharset;
148 bool spellLineEdit;
149 protected slots:
150 void slotSendNow();
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();
171 void slotConfKeys();
172 void slotConfToolbar();
173 void slotNewToolbarConfig();
174 void slotUpdateCheckSpellChecking(bool _b);
176 //------------------------------ </Actions> ----------------------------
178 // GUI
179 void slotSubjectChanged(const QString &t);
180 void slotGroupsChanged(const QString &t);
181 void slotToBtnClicked();
182 void slotGroupsBtnClicked();
184 // external editor
185 void slotEditorFinished(int, QProcess::ExitStatus);
186 void slotCancelEditor();
188 // attachment list
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();
199 // DND handling
200 virtual void slotDragEnterEvent(QDragEnterEvent *);
201 virtual void slotDropEvent(QDropEvent *);
203 void slotUndo();
204 void slotRedo();
205 void slotCut();
206 void slotCopy();
207 void slotPaste();
208 void slotSelectAll();
209 void addRecentAddress();
211 protected:
213 // DND handling
214 virtual void dragEnterEvent(QDragEnterEvent *);
215 virtual void dropEvent(QDropEvent *);
217 signals:
218 void composerDone(KNComposer*);
220 private:
221 bool mFirstEdit;
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.
232 QString mCharset;
235 #if 0
236 /** Message Compser editor, handles tabs (expanding them in textLine(), etc.) */
237 class KNComposer::Editor : public KEdit {
239 Q_OBJECT
241 public:
242 Editor( KNComposer::ComposerView *_composerView, KNComposer *_composer, QWidget *parent = 0 );
243 ~Editor();
244 QStringList processedText();
246 public slots:
247 void slotPasteAsQuotation();
248 void slotFind();
249 void slotSearchAgain();
250 void slotReplace();
251 void slotAddQuotes();
252 void slotRemoveQuotes();
253 void slotAddBox();
254 void slotRemoveBox();
255 void slotRot13();
256 void slotCorrectWord();
258 protected slots:
259 void slotSpellStarted( K3Spell *);
260 void slotSpellDone(const QString &);
261 void slotSpellFinished();
262 virtual void cut();
263 virtual void clear();
264 virtual void del();
265 signals:
266 void sigDragEnterEvent(QDragEnterEvent *);
267 void sigDropEvent(QDropEvent *);
269 protected:
271 // DND handling
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*);
278 private:
279 KNComposer *m_composer;
280 KNComposer::ComposerView *m_composerView;
281 K3Spell *spell;
282 QMap<QString,QStringList> m_replacements;
283 QRegExp m_bound;
285 #endif
287 /** Attachment view of the message composer. */
288 class KNComposer::AttachmentView : public K3ListView {
290 Q_OBJECT
292 public:
293 AttachmentView( QWidget *parent );
294 ~AttachmentView();
296 protected:
297 void keyPressEvent( QKeyEvent *e );
299 signals:
300 void delPressed ( Q3ListViewItem * ); // the user used Key_Delete on a list view item
304 /** Attachment view item. */
305 class KNComposer::AttachmentViewItem : public K3ListViewItem {
307 public:
308 AttachmentViewItem(K3ListView *v, KNAttachment *a);
309 ~AttachmentViewItem();
311 KNAttachment *attachment;
316 /** Attachment properties dialog. */
317 class KNComposer::AttachmentPropertiesDlg : public KDialog {
319 Q_OBJECT
321 public:
322 AttachmentPropertiesDlg( KNAttachment *a, QWidget *parent = 0 );
323 ~AttachmentPropertiesDlg();
325 void apply();
327 protected:
328 KLineEdit *m_imeType,
329 *d_escription;
330 QComboBox *e_ncoding;
332 KNAttachment *a_ttachment;
333 bool n_onTextAsText;
335 protected slots:
336 void accept();
337 void slotMimeTypeTextChanged(const QString &text);
340 //-----------------------------------------------------------------------------
341 /** Line edit for addresses used in the composer. */
342 class KNLineEdit : public KABC::AddressLineEdit
344 Q_OBJECT
345 typedef KABC::AddressLineEdit KNLineEditInherited;
346 public:
348 KNLineEdit( KNComposer::ComposerView *_composerView, bool useCompletion, QWidget *parent = 0 );
349 protected:
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 );
354 private slots:
355 void editRecentAddresses();
356 private:
357 KNComposer::ComposerView *composerView;
360 /** Line edit with on-the-fly spell checking. */
361 class KNLineEditSpell : public KNLineEdit
363 Q_OBJECT
364 public:
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);
372 #endif