2 This file is part of KTnef.
4 Copyright (C) 2002 Michael Goffioul <kdeprint@swing.be>
5 Copyright (c) 2012 Allen Winter <winter@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #include "ktnefview.h"
18 #include "attachpropertydialog.h"
20 #include <KTNEF/KTNEFAttach>
22 #include <KLocalizedString>
28 #include <QMimeDatabase>
31 class Attachment
: public QTreeWidgetItem
34 Attachment(QTreeWidget
*parent
, KTNEFAttach
*attach
);
37 KTNEFAttach
*getAttachment() const
46 Attachment::Attachment(QTreeWidget
*parent
, KTNEFAttach
*attach
)
47 : QTreeWidgetItem(parent
, QStringList(attach
->name())), mAttach(attach
)
49 setText(2, QString::number(mAttach
->size()));
50 if (!mAttach
->fileName().isEmpty()) {
51 setText(0, mAttach
->fileName());
55 QMimeType mimeType
= db
.mimeTypeForName(mAttach
->mimeTag());
56 setText(1, mimeType
.comment());
58 QPixmap pix
= AttachPropertyDialog::loadRenderingPixmap(attach
, qApp
->palette().color(QPalette::Background
));
62 setIcon(0, QIcon::fromTheme(mimeType
.iconName()));
66 Attachment::~Attachment()
70 //----------------------------------------------------------------------------//
72 KTNEFView::KTNEFView(QWidget
*parent
)
75 const QStringList headerLabels
=
76 (QStringList(i18nc("@title:column file name", "File Name"))
77 << i18nc("@title:column file type", "File Type")
78 << i18nc("@title:column file size", "Size"));
79 setHeaderLabels(headerLabels
);
80 setSelectionMode(QAbstractItemView::ExtendedSelection
);
82 setSortingEnabled(true);
83 QTimer::singleShot(0, this, &KTNEFView::adjustColumnWidth
);
86 KTNEFView::~KTNEFView()
90 void KTNEFView::setAttachments(const QList
<KTNEFAttach
*> &list
)
93 if (!list
.isEmpty()) {
94 QList
<KTNEFAttach
*>::ConstIterator it
;
95 QList
<KTNEFAttach
*>::ConstIterator
end(list
.constEnd());
96 for (it
= list
.constBegin(); it
!= end
; ++it
) {
97 new Attachment(this, (*it
));
102 void KTNEFView::resizeEvent(QResizeEvent
*e
)
105 resize(width(), height());
107 QTreeWidget::resizeEvent(e
);
111 QList
<KTNEFAttach
*> KTNEFView::getSelection()
113 mAttachments
.clear();
115 QList
<QTreeWidgetItem
*> list
= selectedItems();
116 if (list
.isEmpty() || !list
.first()) {
120 QList
<QTreeWidgetItem
*>::const_iterator it
;
121 QList
<QTreeWidgetItem
*>::const_iterator
end(list
.constEnd());
122 for (it
= list
.constBegin(); it
!= end
; ++it
) {
123 Attachment
*a
= static_cast<Attachment
*>(*it
);
124 mAttachments
.append(a
->getAttachment());
129 void KTNEFView::startDrag(Qt::DropActions dropAction
)
131 Q_UNUSED(dropAction
);
133 QTreeWidgetItemIterator
it(this, QTreeWidgetItemIterator::Selected
);
134 QList
<KTNEFAttach
*> list
;
136 Attachment
*a
= static_cast<Attachment
*>(*it
);
137 list
<< a
->getAttachment();
140 if (!list
.isEmpty()) {
141 Q_EMIT
dragRequested(list
);
145 void KTNEFView::adjustColumnWidth()
147 const int w
= width() / 2;
148 setColumnWidth(0, w
);
149 setColumnWidth(1, w
/ 2);
150 setColumnWidth(2, w
/ 2);