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 #include "LoadablePartWidget.h"
23 #include "Gui/MessageView.h" // so that the compiler knows that it's a QObject
24 #include "Imap/Model/ItemRoles.h"
25 #include "UiUtils/Formatting.h"
27 #include <QPushButton>
32 LoadablePartWidget::LoadablePartWidget(QWidget
*parent
, Imap::Network::MsgPartNetAccessManager
*manager
, const QModelIndex
&part
,
33 PartWidgetFactory
*factory
, int recursionDepth
,
34 const UiUtils::PartLoadingOptions loadingMode
):
35 QStackedWidget(parent
), manager(manager
), partIndex(part
), m_factory(factory
),
36 m_recursionDepth(recursionDepth
), m_loadingMode(loadingMode
), realPart(0), loadButton(0), m_loadOnShow(false)
38 Q_ASSERT(partIndex
.isValid());
40 QString mimeType
= partIndex
.data(Imap::Mailbox::RolePartMimeType
).toString().toLower();
42 if ((loadingMode
& UiUtils::PART_IS_HIDDEN
) ||
43 (loadingMode
& UiUtils::PART_IGNORE_CLICKTHROUGH
) ||
44 partIndex
.data(Imap::Mailbox::RoleIsFetched
).toBool()) {
47 loadButton
= new QPushButton(tr("Load %1 (%2)").arg(partIndex
.data(Imap::Mailbox::RolePartMimeType
).toString(),
48 UiUtils::Formatting::prettySize(partIndex
.data(Imap::Mailbox::RolePartOctets
).toUInt())),
50 connect(loadButton
, &QAbstractButton::clicked
, this, &LoadablePartWidget::loadClicked
);
51 addWidget(loadButton
);
55 void LoadablePartWidget::loadClicked()
57 if (!partIndex
.isValid()) {
59 loadButton
->setEnabled(false);
64 loadButton
->deleteLater();
68 // We have to disable any flags which might cause recursion here
69 realPart
= m_factory
->walk(partIndex
, m_recursionDepth
+ 1,
70 (m_loadingMode
| UiUtils::PART_IGNORE_CLICKTHROUGH
|
71 UiUtils::PART_IGNORE_LOAD_ON_SHOW
)
72 ^ UiUtils::PART_IS_HIDDEN
);
77 QString
LoadablePartWidget::quoteMe() const
79 AbstractPartWidget
*part
= dynamic_cast<AbstractPartWidget
*>(realPart
);
80 return part
? part
->quoteMe() : QString();
83 void LoadablePartWidget::showEvent(QShowEvent
*event
)
85 QStackedWidget::showEvent(event
);
92 void LoadablePartWidget::reloadContents()
94 if (AbstractPartWidget
*w
= dynamic_cast<AbstractPartWidget
*>(realPart
))