/* This file is part of KTnef. Copyright (C) 2002 Michael Goffioul Copyright (c) 2012 Allen Winter This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include "ktnefview.h" #include "attachpropertydialog.h" #include #include #include #include #include #include #include #include class Attachment : public QTreeWidgetItem { public: Attachment( QTreeWidget *parent, KTNEFAttach *attach ); ~Attachment(); KTNEFAttach *getAttachment() const { return mAttach; } private: KTNEFAttach *mAttach; }; Attachment::Attachment( QTreeWidget *parent, KTNEFAttach *attach ) : QTreeWidgetItem( parent, QStringList( attach->name() ) ), mAttach( attach ) { setText( 2, QString::number( mAttach->size() ) ); if ( !mAttach->fileName().isEmpty() ) { setText( 0, mAttach->fileName() ); } KMimeType::Ptr mimeType = KMimeType::mimeType( mAttach->mimeTag() ); setText( 1, mimeType->comment() ); QPixmap pix = AttachPropertyDialog::loadRenderingPixmap( attach, kapp->palette().color( QPalette::Background ) ); if ( !pix.isNull() ) { setIcon( 0, pix ); } else { setIcon( 0, KIcon( mimeType->iconName() ) ); } } Attachment::~Attachment() { } //----------------------------------------------------------------------------// KTNEFView::KTNEFView( QWidget *parent ) : QTreeWidget( parent ) { const QStringList headerLabels = ( QStringList( i18nc( "@title:column file name", "File Name" ) ) << i18nc( "@title:column file type", "File Type" ) << i18nc( "@title:column file size", "Size" ) ); setHeaderLabels( headerLabels ); setSelectionMode( QAbstractItemView::ExtendedSelection ); setDragEnabled( true ); QTimer::singleShot( 0, this, SLOT(adjustColumnWidth()) ); } KTNEFView::~KTNEFView() { } void KTNEFView::setAttachments( const QList& list ) { clear(); if ( !list.isEmpty() ) { QList::ConstIterator it; QList::ConstIterator end(list.constEnd()); for ( it=list.constBegin(); it != end; ++it ) { new Attachment( this, (*it) ); } } } void KTNEFView::resizeEvent( QResizeEvent *e ) { adjustColumnWidth(); resize( width(), height() ); if ( e ) { QTreeWidget::resizeEvent( e ); } } QList KTNEFView::getSelection() { mAttachments.clear(); QList list = selectedItems(); if ( list.isEmpty() || !list.first() ) { return mAttachments; } QList::const_iterator it; QList::const_iterator end(list.constEnd()); for ( it=list.constBegin(); it != end; ++it ) { Attachment *a = static_cast( *it ); mAttachments.append( a->getAttachment() ); } return mAttachments; } void KTNEFView::startDrag( Qt::DropActions dropAction ) { Q_UNUSED( dropAction ); QTreeWidgetItemIterator it( this, QTreeWidgetItemIterator::Selected ); QList list; while ( *it ) { Attachment *a = static_cast( *it ); list << a->getAttachment(); ++it; } if ( !list.isEmpty() ) { emit dragRequested( list ); } } void KTNEFView::adjustColumnWidth() { const int w = width() / 2; setColumnWidth( 0, w ); setColumnWidth( 1, w / 2 ); setColumnWidth( 2, w / 2 ); }