diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 460c52653ab0dcca6f19a4f492ed2c5e4e963ab0 (patch) | |
tree | 67208f7c145782a7e90b123b982ca78d88cc2c87 /kmail/attachmentlistview.cpp | |
download | tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.tar.gz tdepim-460c52653ab0dcca6f19a4f492ed2c5e4e963ab0.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/attachmentlistview.cpp')
-rw-r--r-- | kmail/attachmentlistview.cpp | 146 |
1 files changed, 146 insertions, 0 deletions
diff --git a/kmail/attachmentlistview.cpp b/kmail/attachmentlistview.cpp new file mode 100644 index 000000000..b7c8bdd21 --- /dev/null +++ b/kmail/attachmentlistview.cpp @@ -0,0 +1,146 @@ +/* -*- c++ -*- + attachmentlistview.cpp + + KMail, the KDE mail client. + Copyright (c) 2003 Ingo Kloecker <[email protected]> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License, + version 2.0, as published by the Free Software Foundation. + 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, US +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +// my header file +#include "attachmentlistview.h" + +// other KMail headers +#include "kmmsgbase.h" +#include "kmfolder.h" +#include "kmcommands.h" +#include "kmmsgdict.h" +#include "composer.h" + +// other module headers +#include <maillistdrag.h> +using KPIM::MailListDrag; + +// other KDE headers +#include <kurldrag.h> + +// other Qt headers +#include <qevent.h> +#include <qcstring.h> +#include <qbuffer.h> +#include <qptrlist.h> +#include <qdatastream.h> +#include <qstring.h> + +// other headers (none) + + +namespace KMail { + +AttachmentListView::AttachmentListView( KMail::Composer * composer, + QWidget* parent, + const char* name ) + : KListView( parent, name ), + mComposer( composer ) +{ + setAcceptDrops( true ); + setDragEnabled( true ); +} + +//----------------------------------------------------------------------------- + +AttachmentListView::~AttachmentListView() +{ +} + +//----------------------------------------------------------------------------- + +void AttachmentListView::contentsDragEnterEvent( QDragEnterEvent* e ) +{ + if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) ) + e->accept( true ); + else + KListView::dragEnterEvent( e ); +} + +//----------------------------------------------------------------------------- + +void AttachmentListView::contentsDragMoveEvent( QDragMoveEvent* e ) +{ + if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) ) + e->accept( true ); + else + KListView::dragMoveEvent( e ); +} + +//----------------------------------------------------------------------------- + +void AttachmentListView::contentsDropEvent( QDropEvent* e ) +{ + if( e->provides( MailListDrag::format() ) ) { + // Decode the list of serial numbers stored as the drag data + QByteArray serNums; + MailListDrag::decode( e, serNums ); + QBuffer serNumBuffer( serNums ); + serNumBuffer.open( IO_ReadOnly ); + QDataStream serNumStream( &serNumBuffer ); + Q_UINT32 serNum; + KMFolder *folder = 0; + int idx; + QPtrList<KMMsgBase> messageList; + while( !serNumStream.atEnd() ) { + KMMsgBase *msgBase = 0; + serNumStream >> serNum; + KMMsgDict::instance()->getLocation( serNum, &folder, &idx ); + if( folder ) + msgBase = folder->getMsgBase( idx ); + if( msgBase ) + messageList.append( msgBase ); + } + serNumBuffer.close(); + uint identity = folder ? folder->identity() : 0; + KMCommand *command = new KMForwardAttachedCommand( mComposer, messageList, + identity, mComposer ); + command->start(); + } + else if( KURLDrag::canDecode( e ) ) { + KURL::List urlList; + if( KURLDrag::decode( e, urlList ) ) { + for( KURL::List::Iterator it = urlList.begin(); + it != urlList.end(); ++it ) { + mComposer->addAttach( *it ); + } + } + } + else { + KListView::dropEvent( e ); + } +} + +//----------------------------------------------------------------------------- + +void AttachmentListView::keyPressEvent( QKeyEvent * e ) +{ + if ( e->key() == Key_Delete ) { + emit attachmentDeleted(); + } +} + +/*virtual*/ +void AttachmentListView::startDrag() +{ + emit dragStarted(); +} + +} // namespace KMail + +#include "attachmentlistview.moc" |