Implement #57688: drag and drop files to the attachment section of the composer
The only real changes in kmcomposewin.* are - QListView *mAtmListBox; + KMail::AttachmentListView* mAtmListView; in kmcomposewin.h and - mAtmListBox = new QListView(mMainWidget, "mAtmListBox"); + mAtmListView = new AttachmentListView( this, mMainWidget, + "attachment list view" ); in kmcomposewin.cpp. All other changes in kmcomposewin.cpp are just mAtmListBox -> mAtmListView svn path=/trunk/kdepim/; revision=223858wilder-work
parent
c750182b9a
commit
f53efff86c
5 changed files with 243 additions and 53 deletions
@ -0,0 +1,130 @@ |
||||
/* -*- c++ -*-
|
||||
attachmentlistview.cpp |
||||
|
||||
KMail, the KDE mail client. |
||||
Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org> |
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "kmcomposewin.h" |
||||
|
||||
// other module headers (none)
|
||||
|
||||
// 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( KMComposeWin* composer, |
||||
QWidget* parent, |
||||
const char* name ) |
||||
: AttachmentListViewInherited( parent, name ), |
||||
mComposer( composer ) |
||||
{ |
||||
setAcceptDrops( true ); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
AttachmentListView::~AttachmentListView() |
||||
{ |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AttachmentListView::contentsDragEnterEvent( QDragEnterEvent* e ) |
||||
{ |
||||
if( e->format( 0 ) |
||||
&& ( e->format( 0 ) == QString( "x-kmail-drag/message" ) ) ) |
||||
e->accept( true ); |
||||
else |
||||
AttachmentListViewInherited::dragEnterEvent( e ); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AttachmentListView::contentsDragMoveEvent( QDragMoveEvent* e ) |
||||
{ |
||||
if( e->format( 0 ) |
||||
&& ( e->format( 0 ) == QString( "x-kmail-drag/message" ) ) ) |
||||
e->accept( true ); |
||||
else |
||||
AttachmentListViewInherited::dragMoveEvent( e ); |
||||
} |
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void AttachmentListView::contentsDropEvent( QDropEvent* e ) |
||||
{ |
||||
if( e->format( 0 ) |
||||
&& ( e->format( 0 ) == QString( "x-kmail-drag/message" ) ) ) { |
||||
// Decode the list of serial numbers stored as the drag data
|
||||
QByteArray serNums = e->encodedData( "x-kmail-drag/message" ); |
||||
QBuffer serNumBuffer( serNums ); |
||||
serNumBuffer.open( IO_ReadOnly ); |
||||
QDataStream serNumStream( &serNumBuffer ); |
||||
unsigned long serNum; |
||||
KMFolder *folder = 0; |
||||
int idx; |
||||
QPtrList<KMMsgBase> messageList; |
||||
while( !serNumStream.atEnd() ) { |
||||
KMMsgBase *msgBase = 0; |
||||
serNumStream >> serNum; |
||||
kernel->msgDict()->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 { |
||||
AttachmentListViewInherited::dropEvent( e ); |
||||
} |
||||
} |
||||
|
||||
|
||||
}; // namespace KMail
|
||||
|
||||
@ -0,0 +1,48 @@ |
||||
/* -*- c++ -*-
|
||||
attachmentlistview.h |
||||
|
||||
KMail, the KDE mail client. |
||||
Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org> |
||||
|
||||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US |
||||
*/ |
||||
|
||||
|
||||
#ifndef _KMAIL_ATTACHMENTLISTVIEW_H_ |
||||
#define _KMAIL_ATTACHMENTLISTVIEW_H_ |
||||
|
||||
#include <klistview.h> |
||||
|
||||
class QDragEnterEvent; |
||||
class QDragMoveEvent; |
||||
class QDropEvent; |
||||
class KMComposeWin; |
||||
|
||||
namespace KMail { |
||||
|
||||
#define AttachmentListViewInherited KListView |
||||
class AttachmentListView : public AttachmentListViewInherited |
||||
{ |
||||
public: |
||||
AttachmentListView( KMComposeWin* composer = 0, QWidget* parent = 0, |
||||
const char* name = 0 ); |
||||
virtual ~AttachmentListView(); |
||||
|
||||
/** Drag and drop methods */ |
||||
void contentsDragEnterEvent( QDragEnterEvent* ); |
||||
void contentsDragMoveEvent( QDragMoveEvent* ); |
||||
void contentsDropEvent( QDropEvent* ); |
||||
|
||||
private: |
||||
KMComposeWin* mComposer; |
||||
}; |
||||
|
||||
}; // namespace KMail
|
||||
|
||||
#endif // _KMAIL_ATTACHMENTLISTVIEW_H_
|
||||
|
||||
Loading…
Reference in new issue