[kde-doc-english] [trojita] src/Gui: GUI: show inline attachments with the usual buttons suggesting that they are, in fact, attachments
Jan Kundrát
jkt at flaska.net
Fri Aug 9 16:30:10 UTC 2013
Git commit 940acd9ee4d399308213de76a34577872f345904 by Jan Kundrát.
Committed on 04/08/2013 at 21:27.
Pushed by jkt into branch 'master'.
GUI: show inline attachments with the usual buttons suggesting that they are, in fact, attachments
M +19 -3 src/Gui/AttachmentView.cpp
M +4 -1 src/Gui/AttachmentView.h
M +8 -2 src/Gui/PartWidgetFactory.cpp
http://commits.kde.org/trojita/940acd9ee4d399308213de76a34577872f345904
diff --git a/src/Gui/AttachmentView.cpp b/src/Gui/AttachmentView.cpp
index 7e1dff0..4189eb4 100644
--- a/src/Gui/AttachmentView.cpp
+++ b/src/Gui/AttachmentView.cpp
@@ -49,12 +49,22 @@
namespace Gui
{
-AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &partIndex):
+AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager,
+ const QModelIndex &partIndex, QWidget *contentWidget):
QWidget(parent), m_partIndex(partIndex), m_downloadButton(0), m_downloadAttachment(0),
- m_openAttachment(0), m_netAccess(manager), m_openingManager(0), m_tmpFile(0)
+ m_openAttachment(0), m_showHideAttachment(0), m_netAccess(manager), m_openingManager(0), m_tmpFile(0),
+ m_contentWidget(contentWidget)
{
m_openingManager = new Imap::Network::FileDownloadManager(this, m_netAccess, m_partIndex);
- QHBoxLayout *layout = new QHBoxLayout(this);
+
+ QVBoxLayout *contentLayout = new QVBoxLayout(this);
+ QWidget *attachmentControls = new QWidget();
+ contentLayout->addWidget(attachmentControls);
+ if (m_contentWidget) {
+ contentLayout->addWidget(m_contentWidget);
+ }
+
+ QHBoxLayout *layout = new QHBoxLayout(attachmentControls);
// Icon on the left
QLabel *lbl = new QLabel();
@@ -105,6 +115,12 @@ AttachmentView::AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessM
m_openAttachment = menu->addAction(tr("Open Directly"));
connect(m_downloadAttachment, SIGNAL(triggered()), this, SLOT(slotDownloadAttachment()));
connect(m_openAttachment, SIGNAL(triggered()), this, SLOT(slotOpenAttachment()));
+ if (m_contentWidget) {
+ m_showHideAttachment = menu->addAction(loadIcon(QLatin1String("view-preview")), tr("Show Preview"));
+ m_showHideAttachment->setCheckable(true);
+ m_showHideAttachment->setChecked(!m_contentWidget->isHidden());
+ connect(m_showHideAttachment, SIGNAL(triggered(bool)), m_contentWidget, SLOT(setVisible(bool)));
+ }
m_downloadButton->setMenu(menu);
m_downloadButton->setDefaultAction(m_downloadAttachment);
diff --git a/src/Gui/AttachmentView.h b/src/Gui/AttachmentView.h
index 7dd2755..b84aa61 100644
--- a/src/Gui/AttachmentView.h
+++ b/src/Gui/AttachmentView.h
@@ -54,7 +54,8 @@ class AttachmentView : public QWidget
{
Q_OBJECT
public:
- AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &m_partIndex);
+ AttachmentView(QWidget *parent, Imap::Network::MsgPartNetAccessManager *manager, const QModelIndex &m_partIndex,
+ QWidget *contentWidget);
protected:
virtual void mousePressEvent(QMouseEvent *event);
private slots:
@@ -72,11 +73,13 @@ private:
QAction *m_downloadAttachment;
QAction *m_openAttachment;
+ QAction *m_showHideAttachment;
Imap::Network::MsgPartNetAccessManager *m_netAccess;
Imap::Network::FileDownloadManager *m_openingManager;
QTemporaryFile *m_tmpFile;
+ QWidget *m_contentWidget;
AttachmentView(const AttachmentView &); // don't implement
AttachmentView &operator=(const AttachmentView &); // don't implement
diff --git a/src/Gui/PartWidgetFactory.cpp b/src/Gui/PartWidgetFactory.cpp
index f739c41..ca1f33e 100644
--- a/src/Gui/PartWidgetFactory.cpp
+++ b/src/Gui/PartWidgetFactory.cpp
@@ -161,7 +161,8 @@ QWidget *PartWidgetFactory::create(const QModelIndex &partIndex, int recursionDe
// The problem is that some nasty MUAs (hint hint Thunderbird) would
// happily attach a .tar.gz and call it "inline"
- if (showInline && recognizedMimeType) {
+ if (showInline && recognizedMimeType && partIndex.data(Imap::Mailbox::RolePartFileName).toString().isEmpty()) {
+ // showing inline without any decorations whatsoever
const Imap::Mailbox::Model *constModel = 0;
Imap::Mailbox::TreeItemPart *part = dynamic_cast<Imap::Mailbox::TreeItemPart *>(Imap::Mailbox::Model::realTreeItem(partIndex, &constModel));
Imap::Mailbox::Model *model = const_cast<Imap::Mailbox::Model *>(constModel);
@@ -186,7 +187,12 @@ QWidget *PartWidgetFactory::create(const QModelIndex &partIndex, int recursionDe
}
return widget;
} else {
- return new AttachmentView(0, manager, partIndex);
+ QWidget *contentWidget = recognizedMimeType ?
+ new LoadablePartWidget(0, manager, partIndex, m_messageView, LoadablePartWidget::LOAD_ON_SHOW) : 0;
+ if (contentWidget && !showInline) {
+ contentWidget->hide();
+ }
+ return new AttachmentView(0, manager, partIndex, contentWidget);
}
}
QLabel *lbl = new QLabel(mimeType, 0);
More information about the kde-doc-english
mailing list