Propagate color of selected messages too
[trojita.git] / src / Gui / ComposeWidget.h
blobee3cb3dd6ced847fb14a6fc6bd221bb329decf94
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 "Plugins/AddressbookPlugin.h"
38 namespace Ui
40 class ComposeWidget;
43 class QAbstractListModel;
44 class QActionGroup;
45 class QComboBox;
46 class QLineEdit;
47 class QMenu;
48 class QPushButton;
49 class QSettings;
50 class QToolButton;
52 namespace Composer {
53 class Submission;
56 namespace MSA {
57 class MSAFactory;
60 namespace Gui
63 class MainWindow;
65 class InhibitComposerDirtying;
67 class ComposerSaveState;
69 /** @short A "Compose New Mail..." dialog
71 Implements a widget which can act as a standalone window for composing e-mail messages.
72 Uses Imap::Mailbox::MessageComposer as a backend for composing a message. @see Imap::Mailbox::MessageComposer
75 class ComposeWidget : public QWidget
77 Q_OBJECT
78 public:
79 ~ComposeWidget();
80 static ComposeWidget *warnIfMsaNotConfigured(ComposeWidget *widget, MainWindow *mainWindow);
81 static ComposeWidget *createDraft(MainWindow *mainWindow, const QString &path);
82 static ComposeWidget *createBlank(MainWindow *mainWindow);
83 static ComposeWidget *createFromUrl(MainWindow *mainWindow, const QUrl &url);
84 static ComposeWidget *createReply(MainWindow *mainWindow, const Composer::ReplyMode &mode, const QModelIndex &replyingToMessage,
85 const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
86 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
87 static ComposeWidget *createForward(MainWindow *mainWindow, const Composer::ForwardMode mode, const QModelIndex &forwardingMessage,
88 const QString &subject, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
89 void placeOnMainWindow();
90 protected:
91 void changeEvent(QEvent *e);
92 void closeEvent(QCloseEvent *ce);
93 bool eventFilter(QObject *o, QEvent *e);
95 private slots:
96 void calculateMaxVisibleRecipients();
97 void collapseRecipients();
98 void completeRecipient(QAction *act);
99 void completeRecipients(const QString &text);
100 void send();
101 void gotError(const QString &error);
102 void sent();
103 void updateRecipientList();
104 void scrollRecipients(int);
105 void handleFocusChange();
106 void scrollToFocus();
107 void slotFadeFinished();
109 void slotCheckAddressOfSender();
110 void slotCheckAddress(QLineEdit *edit);
112 void slotAskForFileAttachment();
113 void slotAttachFiles(QList<QUrl> urls);
115 void slotUpdateSignature();
116 void updateWindowTitle();
118 void autoSaveDraft();
119 void setMessageUpdated();
121 void setUiWidgetsEnabled(const bool enabled);
123 void onCompletionAvailable(const Plugins::NameEmailList &completion);
124 void onCompletionFailed(Plugins::AddressbookJob::Error error);
126 void passwordRequested(const QString &user, const QString &host);
127 void passwordError();
128 void toggleReplyMarking();
129 void updateReplyMarkingAction();
130 void updateReplyMode();
131 void markReplyModeHandpicked();
133 private:
134 ComposeWidget(MainWindow *mainWindow, MSA::MSAFactory *msaFactory);
135 void setResponseData(const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
136 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references,
137 const QModelIndex &replyingToMessage);
138 bool setReplyMode(const Composer::ReplyMode mode);
140 static QByteArray extractMailAddress(const QString &text, bool &ok);
141 static Composer::RecipientKind recipientKindForNextRow(const Composer::RecipientKind kind);
142 void addRecipient(int position, Composer::RecipientKind kind, const QString &address);
143 bool parseRecipients(QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > &results, QString &errorMessage);
144 void removeRecipient(int position);
145 void fadeIn(QWidget *w);
146 void askPassword(const QString &user, const QString &host);
148 bool buildMessageData();
149 bool shouldBuildMessageLocally() const;
151 void saveDraft(const QString &path);
152 void loadDraft(const QString &path);
154 Ui::ComposeWidget *ui;
155 QPushButton *sendButton;
156 QPushButton *cancelButton;
157 QToolButton *m_markButton;
158 QActionGroup *m_markAsReply;
159 QAction *m_actionStandalone;
160 QAction *m_actionInReplyTo;
161 QAction *m_actionToggleMarking;
162 QToolButton *m_replyModeButton;
163 QActionGroup *m_replyModeActions;
164 QAction *m_actionHandPickedRecipients;
165 QAction *m_actionReplyModePrivate;
166 QAction *m_actionReplyModeAllButMe;
167 QAction *m_actionReplyModeAll;
168 QAction *m_actionReplyModeList;
169 typedef QPair<QComboBox*, QLineEdit*> Recipient;
170 QList<Recipient> m_recipients;
171 QTimer *m_recipientListUpdateTimer;
172 QPointer<QWidget> m_lastFocusedRecipient;
173 int m_maxVisibleRecipients;
175 bool m_sentMail;
176 bool m_explicitDraft;
177 QString m_autoSavePath;
179 QList<QByteArray> m_inReplyTo;
180 QList<QByteArray> m_references;
181 QPersistentModelIndex m_replyingToMessage;
183 std::unique_ptr<ComposerSaveState> m_saveState;
185 bool m_appendUidReceived;
186 uint m_appendUidValidity;
187 uint m_appendUid;
188 bool m_genUrlAuthReceived;
189 QString m_urlauth;
191 MainWindow *m_mainWindow;
192 QSettings *m_settings;
194 Composer::Submission *m_submission;
196 QMenu *m_completionPopup;
197 QLineEdit *m_completionReceiver;
198 int m_completionCount;
200 QMap<QLineEdit *, Plugins::AddressbookJob *> m_firstCompletionRequests;
201 QMap<QLineEdit *, Plugins::AddressbookJob *> m_secondCompletionRequests;
203 friend class InhibitComposerDirtying;
204 friend class ComposerSaveState;
206 ComposeWidget(const ComposeWidget &); // don't implement
207 ComposeWidget &operator=(const ComposeWidget &); // don't implement
212 #endif // COMPOSEWIDGET_H