kmail

attachmentlistview.cpp

Go to the documentation of this file.
00001 /*  -*- c++ -*-
00002     attachmentlistview.cpp
00003 
00004     KMail, the KDE mail client.
00005     Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
00006 
00007     This program is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU General Public License,
00009     version 2.0, as published by the Free Software Foundation.
00010     You should have received a copy of the GNU General Public License
00011     along with this program; if not, write to the Free Software Foundation,
00012     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00013 */
00014 
00015 #ifdef HAVE_CONFIG_H
00016 #include <config.h>
00017 #endif
00018 
00019 // my header file
00020 #include "attachmentlistview.h"
00021 
00022 // other KMail headers
00023 #include "kmmsgbase.h"
00024 #include "kmfolder.h"
00025 #include "kmcommands.h"
00026 #include "kmmsgdict.h"
00027 #include "composer.h"
00028 
00029 // other module headers
00030 #include <maillistdrag.h>
00031 using KPIM::MailListDrag;
00032 
00033 // other KDE headers
00034 #include <kurldrag.h>
00035 
00036 // other Qt headers
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 // other headers (none)
00045 
00046 
00047 namespace KMail {
00048 
00049 AttachmentListView::AttachmentListView( KMail::Composer * composer,
00050                                         QWidget* parent,
00051                                         const char* name )
00052   : KListView( parent, name ),
00053     mComposer( composer )
00054 {
00055   setAcceptDrops( true );
00056   setDragEnabled( true );
00057 }
00058 
00059 //-----------------------------------------------------------------------------
00060 
00061 AttachmentListView::~AttachmentListView()
00062 {
00063 }
00064 
00065 //-----------------------------------------------------------------------------
00066 
00067 void AttachmentListView::contentsDragEnterEvent( QDragEnterEvent* e )
00068 {
00069   if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
00070     e->accept( true );
00071   else
00072     KListView::dragEnterEvent( e );
00073 }
00074 
00075 //-----------------------------------------------------------------------------
00076 
00077 void AttachmentListView::contentsDragMoveEvent( QDragMoveEvent* e )
00078 {
00079   if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
00080     e->accept( true );
00081   else
00082     KListView::dragMoveEvent( e );
00083 }
00084 
00085 //-----------------------------------------------------------------------------
00086 
00087 void AttachmentListView::contentsDropEvent( QDropEvent* e )
00088 {
00089   if( e->provides( MailListDrag::format() ) ) {
00090     // Decode the list of serial numbers stored as the drag data
00091     QByteArray serNums;
00092     MailListDrag::decode( e, serNums );
00093     QBuffer serNumBuffer( serNums );
00094     serNumBuffer.open( IO_ReadOnly );
00095     QDataStream serNumStream( &serNumBuffer );
00096     Q_UINT32 serNum;
00097     KMFolder *folder = 0;
00098     int idx;
00099     QPtrList<KMMsgBase> messageList;
00100     while( !serNumStream.atEnd() ) {
00101       KMMsgBase *msgBase = 0;
00102       serNumStream >> serNum;
00103       KMMsgDict::instance()->getLocation( serNum, &folder, &idx );
00104       if( folder )
00105         msgBase = folder->getMsgBase( idx );
00106       if( msgBase )
00107         messageList.append( msgBase );
00108     }
00109     serNumBuffer.close();
00110     uint identity = folder ? folder->identity() : 0;
00111     KMCommand *command = new KMForwardAttachedCommand( mComposer, messageList,
00112                                                        identity, mComposer );
00113     command->start();
00114   }
00115   else if( KURLDrag::canDecode( e ) ) {
00116     KURL::List urlList;
00117     if( KURLDrag::decode( e, urlList ) ) {
00118       for( KURL::List::Iterator it = urlList.begin();
00119            it != urlList.end(); ++it ) {
00120         mComposer->addAttach( *it );
00121       }
00122     }
00123   }
00124   else {
00125     KListView::dropEvent( e );
00126   }
00127 }
00128 
00129 //-----------------------------------------------------------------------------
00130 
00131 void AttachmentListView::keyPressEvent( QKeyEvent * e )
00132 {
00133   if ( e->key() == Key_Delete ) {
00134     emit attachmentDeleted();
00135   }
00136 }
00137 
00138 /*virtual*/
00139 void AttachmentListView::startDrag()
00140 {
00141     emit dragStarted();
00142 }
00143 
00144 } // namespace KMail
00145 
00146 #include "attachmentlistview.moc"