Propagate color of selected messages too
[trojita.git] / src / Gui / MessageSourceWidget.cpp
blob23295e84db9b12e8185d1f567ad54ae1dd2f0405
1 /* Copyright (C) 2013 Ahmed Ibrahim Khalil <ahmedibrahimkhali@gmail.com>
2 Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org>
4 This file is part of the Trojita Qt IMAP e-mail client,
5 http://trojita.flaska.net/
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of
10 the License or (at your option) version 3 or any later version
11 accepted by the membership of KDE e.V. (or its successor approved
12 by the membership of KDE e.V.), which shall act as a proxy
13 defined in Section 14 of version 3 of the license.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "MessageSourceWidget.h"
25 #include <QAction>
26 #include <QModelIndex>
27 #include <QVBoxLayout>
28 #include <QWebView>
29 #include "Gui/FindBar.h"
30 #include "Gui/Spinner.h"
31 #include "Imap/Model/FullMessageCombiner.h"
32 #include "UiUtils/IconLoader.h"
34 namespace Gui
37 MessageSourceWidget::MessageSourceWidget(QWidget *parent, const QModelIndex &messageIndex)
38 : QWidget(parent)
39 , FindBarMixin(this)
40 , m_combiner(nullptr)
41 , m_loadingSpinner(nullptr)
42 , m_widget(new QWebView(this))
44 setWindowIcon(UiUtils::loadIcon(QStringLiteral("text-x-hex")));
45 Q_ASSERT(messageIndex.isValid());
46 m_widget->page()->setNetworkAccessManager(0);
48 m_loadingSpinner = new Spinner(this);
49 m_loadingSpinner->setText(tr("Fetching\nMessage"));
50 m_loadingSpinner->setType(Spinner::Sun);
51 m_loadingSpinner->start(250);
53 m_combiner = new Imap::Mailbox::FullMessageCombiner(messageIndex, this);
54 connect(m_combiner, &Imap::Mailbox::FullMessageCombiner::completed, this, &MessageSourceWidget::slotCompleted);
55 connect(m_combiner, &Imap::Mailbox::FullMessageCombiner::failed, this, &MessageSourceWidget::slotError);
56 m_combiner->load();
58 auto find = new QAction(UiUtils::loadIcon(QStringLiteral("edit-find")), tr("Search..."), this);
59 find->setShortcut(tr("Ctrl+F"));
60 connect(find, &QAction::triggered, this, [this]() {
61 searchRequestedBy(m_widget);
62 });
63 addAction(find);
65 auto layout = new QVBoxLayout(this);
66 layout->setContentsMargins(0, 0, 0, 0);
67 layout->addWidget(m_widget, 1);
68 layout->addWidget(m_findBar);
69 setLayout(layout);
72 void MessageSourceWidget::slotCompleted()
74 m_loadingSpinner->stop();
75 m_widget->setContent(m_combiner->data(), QStringLiteral("text/plain"));
78 void MessageSourceWidget::slotError(const QString &message)
80 m_loadingSpinner->stop();
81 m_widget->setContent(message.toUtf8(), QStringLiteral("text/plain; charset=utf-8"));