Merge "persistent color scheme selection"
[trojita.git] / src / Gui / ComposeWidget.h
blob37cd4a5cdfff93422f90ef667b020da757477698
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 "Common/Logging.h"
35 #include "Composer/Recipients.h"
36 #include "Composer/MessageComposer.h"
37 #include "Plugins/AddressbookPlugin.h"
40 namespace Ui
42 class ComposeWidget;
45 class QAbstractListModel;
46 class QActionGroup;
47 class QComboBox;
48 class QLineEdit;
49 class QMenu;
50 class QPushButton;
51 class QSettings;
52 class QToolButton;
54 namespace Composer {
55 class Submission;
58 namespace MSA {
59 class MSAFactory;
62 namespace Gui
65 class MainWindow;
67 class InhibitComposerDirtying;
69 class ComposerSaveState;
71 /** @short A "Compose New Mail..." dialog
73 Implements a widget which can act as a standalone window for composing e-mail messages.
74 Uses Imap::Mailbox::MessageComposer as a backend for composing a message. @see Imap::Mailbox::MessageComposer
77 class ComposeWidget : public QWidget
79 Q_OBJECT
80 public:
81 ~ComposeWidget();
82 static ComposeWidget *warnIfMsaNotConfigured(ComposeWidget *widget, MainWindow *mainWindow);
83 static ComposeWidget *createDraft(MainWindow *mainWindow, const QString &path);
84 static ComposeWidget *createBlank(MainWindow *mainWindow);
85 static ComposeWidget *createFromUrl(MainWindow *mainWindow, const QUrl &url);
86 static ComposeWidget *createReply(MainWindow *mainWindow, const Composer::ReplyMode &mode, const QModelIndex &replyingToMessage,
87 const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
88 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
89 static ComposeWidget *createForward(MainWindow *mainWindow, const Composer::ForwardMode mode, const QModelIndex &forwardingMessage,
90 const QString &subject, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references);
91 static ComposeWidget *createFromReadOnly(MainWindow *mainWindow, const QModelIndex &messageRoot, const QList<QPair<Composer::RecipientKind, QString>> &recipients);
92 void placeOnMainWindow();
93 protected:
94 void changeEvent(QEvent *e);
95 void closeEvent(QCloseEvent *ce);
96 bool eventFilter(QObject *o, QEvent *e);
98 private slots:
99 void calculateMaxVisibleRecipients();
100 void collapseRecipients();
101 void completeRecipient(QAction *act);
102 void completeRecipients(const QString &text);
103 void send();
104 void gotError(const QString &error);
105 void sent();
106 void updateRecipientList();
107 void scrollRecipients(int);
108 void gotoNextInputLineFrom(QWidget *w);
109 void handleFocusChange();
110 void scrollToFocus();
111 void slotFadeFinished();
113 void slotCheckAddressOfSender();
114 void slotCheckAddress(QLineEdit *edit);
116 void slotAskForFileAttachment();
117 void slotAttachFiles(QList<QUrl> urls);
119 void slotUpdateSignature();
120 void updateWindowTitle();
122 void autoSaveDraft();
123 void setMessageUpdated();
125 void setUiWidgetsEnabled(const bool enabled);
127 void onCompletionAvailable(const Plugins::NameEmailList &completion);
128 void onCompletionFailed(Plugins::AddressbookJob::Error error);
130 void passwordRequested(const QString &user, const QString &host);
131 void passwordError();
132 void toggleReplyMarking();
133 void updateReplyMarkingAction();
134 void updateReplyMode();
135 void markReplyModeHandpicked();
137 signals:
138 void logged(const Common::LogKind kind, const QString& source, const QString& message);
140 private:
141 ComposeWidget(MainWindow *mainWindow, std::shared_ptr<Composer::AbstractComposer> messageComposer, MSA::MSAFactory *msaFactory);
142 void setResponseData(const QList<QPair<Composer::RecipientKind, QString> > &recipients, const QString &subject,
143 const QString &body, const QList<QByteArray> &inReplyTo, const QList<QByteArray> &references,
144 const QModelIndex &replyingToMessage);
145 bool setReplyMode(const Composer::ReplyMode mode);
147 static QByteArray extractMailAddress(const QString &text, bool &ok);
148 static Composer::RecipientKind recipientKindForNextRow(const Composer::RecipientKind kind);
149 void addRecipient(int position, Composer::RecipientKind kind, const QString &address);
150 bool parseRecipients(QList<QPair<Composer::RecipientKind, Imap::Message::MailAddress> > &results, QString &errorMessage);
151 void removeRecipient(int position);
152 void fadeIn(QWidget *w);
153 void askPassword(const QString &user, const QString &host);
155 bool buildMessageData();
156 bool shouldBuildMessageLocally() const;
158 void saveDraft(const QString &path);
159 void loadDraft(const QString &path);
161 std::shared_ptr<Composer::MessageComposer> interactiveComposer();
163 Ui::ComposeWidget *ui;
164 QPushButton *sendButton;
165 QPushButton *cancelButton;
166 QToolButton *m_markButton;
167 QActionGroup *m_markAsReply;
168 QAction *m_actionStandalone;
169 QAction *m_actionInReplyTo;
170 QAction *m_actionToggleMarking;
171 QToolButton *m_replyModeButton;
172 QActionGroup *m_replyModeActions;
173 QAction *m_actionHandPickedRecipients;
174 QAction *m_actionReplyModePrivate;
175 QAction *m_actionReplyModeAllButMe;
176 QAction *m_actionReplyModeAll;
177 QAction *m_actionReplyModeList;
178 typedef QPair<QComboBox*, QLineEdit*> Recipient;
179 QList<Recipient> m_recipients;
180 QTimer *m_recipientListUpdateTimer;
181 QPointer<QWidget> m_lastFocusedRecipient;
182 int m_maxVisibleRecipients;
184 bool m_sentMail;
185 bool m_explicitDraft;
186 QString m_autoSavePath;
188 QList<QByteArray> m_inReplyTo;
189 QList<QByteArray> m_references;
190 QPersistentModelIndex m_replyingToMessage;
192 std::unique_ptr<ComposerSaveState> m_saveState;
194 bool m_appendUidReceived;
195 uint m_appendUidValidity;
196 uint m_appendUid;
197 bool m_genUrlAuthReceived;
198 QString m_urlauth;
200 MainWindow *m_mainWindow;
201 QSettings *m_settings;
203 std::shared_ptr<Composer::AbstractComposer> m_composer;
204 Composer::Submission *m_submission;
206 QMenu *m_completionPopup;
207 QLineEdit *m_completionReceiver;
208 int m_completionCount;
210 QMap<QLineEdit *, Plugins::AddressbookJob *> m_firstCompletionRequests;
211 QMap<QLineEdit *, Plugins::AddressbookJob *> m_secondCompletionRequests;
213 friend class InhibitComposerDirtying;
214 friend class ComposerSaveState;
216 ComposeWidget(const ComposeWidget &); // don't implement
217 ComposeWidget &operator=(const ComposeWidget &); // don't implement
222 #endif // COMPOSEWIDGET_H