File indexing completed on 2024-11-24 04:53:01
0001 /* Copyright (C) 2006 - 2016 Jan Kundrát <jkt@kde.org> 0002 0003 This file is part of the Trojita Qt IMAP e-mail client, 0004 http://trojita.flaska.net/ 0005 0006 This program is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU General Public License as 0008 published by the Free Software Foundation; either version 2 of 0009 the License or (at your option) version 3 or any later version 0010 accepted by the membership of KDE e.V. (or its successor approved 0011 by the membership of KDE e.V.), which shall act as a proxy 0012 defined in Section 14 of version 3 of the license. 0013 0014 This program is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU General Public License for more details. 0018 0019 You should have received a copy of the GNU General Public License 0020 along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #include "Gui/MessageHeadersWidget.h" 0024 #include <QAction> 0025 #include <QModelIndex> 0026 #include <QVBoxLayout> 0027 #include <QWebView> 0028 #include "Gui/FindBar.h" 0029 #include "Imap/Model/ItemRoles.h" 0030 #include "Imap/Model/MailboxTree.h" 0031 #include "Imap/Network/MsgPartNetAccessManager.h" 0032 #include "UiUtils/IconLoader.h" 0033 0034 namespace Gui { 0035 0036 MessageHeadersWidget::MessageHeadersWidget(QWidget *parent, const QModelIndex &messageIndex) 0037 : QWidget(parent) 0038 , FindBarMixin(this) 0039 , m_widget(new QWebView(this)) 0040 0041 { 0042 setWindowIcon(UiUtils::loadIcon(QStringLiteral("text-x-hex"))); 0043 //: Translators: %1 is the UID of a message (a number) and %2 is the name of a mailbox. 0044 setWindowTitle(tr("Message headers of UID %1 in %2").arg( 0045 QString::number(messageIndex.data(Imap::Mailbox::RoleMessageUid).toUInt()), 0046 messageIndex.parent().parent().data(Imap::Mailbox::RoleMailboxName).toString() 0047 )); 0048 Q_ASSERT(messageIndex.isValid()); 0049 0050 auto netAccess = new Imap::Network::MsgPartNetAccessManager(this); 0051 netAccess->setModelMessage(messageIndex); 0052 m_widget->page()->setNetworkAccessManager(netAccess); 0053 m_widget->setUrl(QUrl(QStringLiteral("trojita-imap://msg/HEADER"))); 0054 0055 auto find = new QAction(UiUtils::loadIcon(QStringLiteral("edit-find")), tr("Search..."), this); 0056 find->setShortcut(tr("Ctrl+F")); 0057 connect(find, &QAction::triggered, this, [this]() { 0058 searchRequestedBy(m_widget); 0059 }); 0060 addAction(find); 0061 0062 auto layout = new QVBoxLayout(this); 0063 layout->setContentsMargins(0, 0, 0, 0); 0064 layout->addWidget(m_widget, 1); 0065 layout->addWidget(m_findBar); 0066 setLayout(layout); 0067 } 0068 0069 }