attachmentlistview.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifdef HAVE_CONFIG_H
00016 #include <config.h>
00017 #endif
00018
00019
00020 #include "attachmentlistview.h"
00021
00022
00023 #include "kmmsgbase.h"
00024 #include "kmfolder.h"
00025 #include "kmcommands.h"
00026 #include "kmmsgdict.h"
00027 #include "kmcomposewin.h"
00028
00029
00030 #include <maillistdrag.h>
00031 using KPIM::MailListDrag;
00032
00033
00034 #include <kurldrag.h>
00035
00036
00037 #include <qevent.h>
00038 #include <qcstring.h>
00039 #include <qbuffer.h>
00040 #include <qptrlist.h>
00041 #include <qdatastream.h>
00042 #include <qstring.h>
00043
00044
00045
00046
00047 namespace KMail {
00048
00049 AttachmentListView::AttachmentListView( KMComposeWin* composer,
00050 QWidget* parent,
00051 const char* name )
00052 : KListView( parent, name ),
00053 mComposer( composer )
00054 {
00055 setAcceptDrops( true );
00056 }
00057
00058
00059
00060 AttachmentListView::~AttachmentListView()
00061 {
00062 }
00063
00064
00065
00066 void AttachmentListView::contentsDragEnterEvent( QDragEnterEvent* e )
00067 {
00068 if( e->provides( MailListDrag::format() ) )
00069 e->accept( true );
00070 else
00071 KListView::dragEnterEvent( e );
00072 }
00073
00074
00075
00076 void AttachmentListView::contentsDragMoveEvent( QDragMoveEvent* e )
00077 {
00078 if( e->provides( MailListDrag::format() ) )
00079 e->accept( true );
00080 else
00081 KListView::dragMoveEvent( e );
00082 }
00083
00084
00085
00086 void AttachmentListView::contentsDropEvent( QDropEvent* e )
00087 {
00088 if( e->provides( MailListDrag::format() ) ) {
00089
00090 QByteArray serNums;
00091 MailListDrag::decode( e, serNums );
00092 QBuffer serNumBuffer( serNums );
00093 serNumBuffer.open( IO_ReadOnly );
00094 QDataStream serNumStream( &serNumBuffer );
00095 unsigned long serNum;
00096 KMFolder *folder = 0;
00097 int idx;
00098 QPtrList<KMMsgBase> messageList;
00099 while( !serNumStream.atEnd() ) {
00100 KMMsgBase *msgBase = 0;
00101 serNumStream >> serNum;
00102 kmkernel->msgDict()->getLocation( serNum, &folder, &idx );
00103 if( folder )
00104 msgBase = folder->getMsgBase( idx );
00105 if( msgBase )
00106 messageList.append( msgBase );
00107 }
00108 serNumBuffer.close();
00109 uint identity = folder ? folder->identity() : 0;
00110 KMCommand *command = new KMForwardAttachedCommand( mComposer, messageList,
00111 identity, mComposer );
00112 command->start();
00113 }
00114 else if( KURLDrag::canDecode( e ) ) {
00115 KURL::List urlList;
00116 if( KURLDrag::decode( e, urlList ) ) {
00117 for( KURL::List::Iterator it = urlList.begin();
00118 it != urlList.end(); ++it ) {
00119 mComposer->addAttach( *it );
00120 }
00121 }
00122 }
00123 else {
00124 KListView::dropEvent( e );
00125 }
00126 }
00127
00128
00129 }
00130
This file is part of the documentation for kmail Library Version 3.2.2.