kmail

attachmentlistview.cpp
1/*
2 attachmentlistview.cpp
3
4 KMail, the KDE mail client.
5 Copyright (c) 2003 Ingo Kloecker <kloecker@kde.org>
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License,
9 version 2.0, as published by the Free Software Foundation.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
13*/
14
15#ifdef HAVE_CONFIG_H
16#include <config.h>
17#endif
18
19// my header file
20#include "attachmentlistview.h"
21
22// other KMail headers
23#include "kmmsgbase.h"
24#include "kmfolder.h"
25#include "kmcommands.h"
26#include "kmmsgdict.h"
27#include "composer.h"
28
29// other module headers
30#include <maillistdrag.h>
31using KPIM::MailListDrag;
32
33// other KDE headers
34#include <kurldrag.h>
35
36// other TQt headers
37#include <tqevent.h>
38#include <tqcstring.h>
39#include <tqbuffer.h>
40#include <tqptrlist.h>
41#include <tqdatastream.h>
42#include <tqstring.h>
43
44// other headers (none)
45
46
47namespace KMail {
48
49AttachmentListView::AttachmentListView( KMail::Composer * composer,
50 TQWidget* parent,
51 const char* name )
52 : TDEListView( parent, name ),
53 mComposer( composer )
54{
55 setAcceptDrops( true );
56 setDragEnabled( true );
57}
58
59//-----------------------------------------------------------------------------
60
61AttachmentListView::~AttachmentListView()
62{
63}
64
65//-----------------------------------------------------------------------------
66
67void AttachmentListView::contentsDragEnterEvent( TQDragEnterEvent* e )
68{
69 if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
70 e->accept( true );
71 else
72 TDEListView::dragEnterEvent( e );
73}
74
75//-----------------------------------------------------------------------------
76
77void AttachmentListView::contentsDragMoveEvent( TQDragMoveEvent* e )
78{
79 if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
80 e->accept( true );
81 else
82 TDEListView::dragMoveEvent( e );
83}
84
85//-----------------------------------------------------------------------------
86
87void AttachmentListView::contentsDropEvent( TQDropEvent* e )
88{
89 if( e->provides( MailListDrag::format() ) ) {
90 // Decode the list of serial numbers stored as the drag data
91 TQByteArray serNums;
92 MailListDrag::decode( e, serNums );
93 TQBuffer serNumBuffer( serNums );
94 serNumBuffer.open( IO_ReadOnly );
95 TQDataStream serNumStream( &serNumBuffer );
96 TQ_UINT32 serNum;
97 KMFolder *folder = 0;
98 int idx;
99 TQPtrList<KMMsgBase> messageList;
100 while( !serNumStream.atEnd() ) {
101 KMMsgBase *msgBase = 0;
102 serNumStream >> serNum;
103 KMMsgDict::instance()->getLocation( serNum, &folder, &idx );
104 if( folder )
105 msgBase = folder->getMsgBase( idx );
106 if( msgBase )
107 messageList.append( msgBase );
108 }
109 serNumBuffer.close();
110 uint identity = folder ? folder->identity() : 0;
111 KMCommand *command = new KMForwardAttachedCommand( mComposer, messageList,
112 identity, mComposer );
113 command->start();
114 }
115 else if( KURLDrag::canDecode( e ) ) {
116 KURL::List urlList;
117 if( KURLDrag::decode( e, urlList ) ) {
118 for( KURL::List::Iterator it = urlList.begin();
119 it != urlList.end(); ++it ) {
120 mComposer->addAttach( *it );
121 }
122 }
123 }
124 else {
125 TDEListView::dropEvent( e );
126 }
127}
128
129//-----------------------------------------------------------------------------
130
131void AttachmentListView::keyPressEvent( TQKeyEvent * e )
132{
133 if ( e->key() == Key_Delete ) {
134 emit attachmentDeleted();
135 }
136}
137
138/*virtual*/
139void AttachmentListView::startDrag()
140{
141 emit dragStarted();
142}
143
144} // namespace KMail
145
146#include "attachmentlistview.moc"
Mail folder.
Definition: kmfolder.h:69
const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
Definition: kmfolder.cpp:360
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
Definition: kmmsgdict.cpp:319
static const KMMsgDict * instance()
Access the globally unique MessageDict.
Definition: kmmsgdict.cpp:167
folderdiaquotatab.h
Definition: aboutdata.cpp:40