composer: abstract interface for common MessageComposer's methods
[trojita.git] / src / Gui / ComposeWidget.h
blob4d8e8a529e808730da3e0de13e7c8ec8a1ace1a8
1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
3 This file is part of the Trojita Qt IMAP e-mail client,
4 http://trojita.flaska.net/
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of
9 the License or (at your option) version 3 or any later version
10 accepted by the membership of KDE e.V. (or its successor approved
11 by the membership of KDE e.V.), which shall act as a proxy
12 defined in Section 14 of version 3 of the license.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef COMPOSEWIDGET_H
23 #define COMPOSEWIDGET_H
25 #include <memory>
27 #include <QList>
28 #include <QMap>
29 #include <QPersistentModelIndex>
30 #include <QUrl>
31 #include <QPointer>
32 #include <QWidget>
34 #include "Composer/Recipients.h"
35 #include "Composer/MessageComposer.h"
36 #include "Plugins/AddressbookPlugin.h"
39 namespace Ui
41 class ComposeWidget;
44 class QAbstractListModel;
45 class QActionGroup;
46 class QComboBox;
47 class QLineEdit;
48 class QMenu;
49 class QPushButton;
50 class QSettings;
51 class QToolButton;
53 namespace Composer {
54 class Submission;
57 namespace MSA {
58 class MSAFactory;
61 namespace Gui
64 class MainWindow;
66 class InhibitComposerDirtying;
68 class ComposerSaveState;
70 /** @short A "Compose New Mail..." dialog
72 Implements a widget which can act as a standalone window for composing e-mail messages.
73 Uses Imap::Mailbox::MessageComposer as a backend for composing a message. @see Imap::Mailbox::MessageComposer
76 class ComposeWidget : public QWidget
78 Q_OBJECT
79 public:
80 ~ComposeWidget();
81 static ComposeWidget *warnIfMsaNotConfigured(ComposeWidget *widget, MainWindow *mainWindow);
82 static ComposeWidget *createDraft(MainWindow *mainWindow, const QString &path);
83 static ComposeWidget *createBlank(MainWindow *mainWindow);
84 static ComposeWidget *createFromUrl(MainWindow *mainWindow, const QUrl &url);
85 static ComposeWidget *createReply(MainWindow *mainWindow, const Composer::ReplyMode &mode, const QModelIndex &replyingToMessage,
86 const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
87 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
88 static ComposeWidget *createForward(MainWindow *mainWindow, const Composer::ForwardMode mode, const QModelIndex &forwardingMessage,
89 const QString &subject, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
90 void placeOnMainWindow();
91 protected:
92 void changeEvent(QEvent *e);
93 void closeEvent(QCloseEvent *ce);
94 bool eventFilter(QObject *o, QEvent *e);
96 private slots:
97 void calculateMaxVisibleRecipients();
98 void collapseRecipients();
99 void completeRecipient(QAction *act);
100 void completeRecipients(const QString &text);
101 void send();
102 void gotError(const QString &error);
103 void sent();
104 void updateRecipientList();
105 void scrollRecipients(int);
106 void handleFocusChange();
107 void scrollToFocus();
108 void slotFadeFinished();
110 void slotCheckAddressOfSender();
111 void slotCheckAddress(QLineEdit *edit);
113 void slotAskForFileAttachment();
114 void slotAttachFiles(QList<QUrl> urls);
116 void slotUpdateSignature();
117 void updateWindowTitle();
119 void autoSaveDraft();
120 void setMessageUpdated();
122 void setUiWidgetsEnabled(const bool enabled);
124 void onCompletionAvailable(const Plugins::NameEmailList &completion);
125 void onCompletionFailed(Plugins::AddressbookJob::Error error);
127 void passwordRequested(const QString &user, const QString &host);
128 void passwordError();
129 void toggleReplyMarking();
130 void updateReplyMarkingAction();
131 void updateReplyMode();
132 void markReplyModeHandpicked();
134 private:
135 ComposeWidget(MainWindow *mainWindow, MSA::MSAFactory *msaFactory);
136 void setResponseData(const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
137 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references,
138 const QModelIndex &replyingToMessage);
139 bool setReplyMode(const Composer::ReplyMode mode);
141 static QByteArray extractMailAddress(const QString &text, bool &ok);
142 static Composer::RecipientKind recipientKindForNextRow(const Composer::RecipientKind kind);
143 void addRecipient(int position, Composer::RecipientKind kind, const QString &address);
144 bool parseRecipients(QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > &results, QString &errorMessage);
145 void removeRecipient(int position);
146 void fadeIn(QWidget *w);
147 void askPassword(const QString &user, const QString &host);
149 bool buildMessageData();
150 bool shouldBuildMessageLocally() const;
152 void saveDraft(const QString &path);
153 void loadDraft(const QString &path);
155 Ui::ComposeWidget *ui;
156 QPushButton *sendButton;
157 QPushButton *cancelButton;
158 QToolButton *m_markButton;
159 QActionGroup *m_markAsReply;
160 QAction *m_actionStandalone;
161 QAction *m_actionInReplyTo;
162 QAction *m_actionToggleMarking;
163 QToolButton *m_replyModeButton;
164 QActionGroup *m_replyModeActions;
165 QAction *m_actionHandPickedRecipients;
166 QAction *m_actionReplyModePrivate;
167 QAction *m_actionReplyModeAllButMe;
168 QAction *m_actionReplyModeAll;
169 QAction *m_actionReplyModeList;
170 typedef QPair<QComboBox*, QLineEdit*> Recipient;
171 QList<Recipient> m_recipients;
172 QTimer *m_recipientListUpdateTimer;
173 QPointer<QWidget> m_lastFocusedRecipient;
174 int m_maxVisibleRecipients;
176 bool m_sentMail;
177 bool m_explicitDraft;
178 QString m_autoSavePath;
180 QList<QByteArray> m_inReplyTo;
181 QList<QByteArray> m_references;
182 QPersistentModelIndex m_replyingToMessage;
184 std::unique_ptr<ComposerSaveState> m_saveState;
186 bool m_appendUidReceived;
187 uint m_appendUidValidity;
188 uint m_appendUid;
189 bool m_genUrlAuthReceived;
190 QString m_urlauth;
192 MainWindow *m_mainWindow;
193 QSettings *m_settings;
195 Composer::Submission *m_submission;
197 QMenu *m_completionPopup;
198 QLineEdit *m_completionReceiver;
199 int m_completionCount;
201 QMap<QLineEdit *, Plugins::AddressbookJob *> m_firstCompletionRequests;
202 QMap<QLineEdit *, Plugins::AddressbookJob *> m_secondCompletionRequests;
204 friend class InhibitComposerDirtying;
205 friend class ComposerSaveState;
207 ComposeWidget(const ComposeWidget &); // don't implement
208 ComposeWidget &operator=(const ComposeWidget &); // don't implement
213 #endif // COMPOSEWIDGET_H