kmail Library API Documentation

attachmentlistview.cpp

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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "kmcomposewin.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( 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 // Decode the list of serial numbers stored as the drag data 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 } // namespace KMail 00130
KDE Logo
This file is part of the documentation for kmail Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 21 19:46:43 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003