1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/* -*- c++ -*-
attachmentlistview.cpp
KMail, the KDE mail client.
Copyright (c) 2003 Ingo Kloecker <[email protected]>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "composer.h"
// other module headers
#include <maillistdrag.h>
using KPIM::MailListDrag;
// other KDE headers
#include <kurldrag.h>
// other Qt headers
#include <tqevent.h>
#include <tqcstring.h>
#include <tqbuffer.h>
#include <tqptrlist.h>
#include <tqdatastream.h>
#include <tqstring.h>
// other headers (none)
namespace KMail {
AttachmentListView::AttachmentListView( KMail::Composer * composer,
TQWidget* parent,
const char* name )
: KListView( parent, name ),
mComposer( composer )
{
setAcceptDrops( true );
setDragEnabled( true );
}
//-----------------------------------------------------------------------------
AttachmentListView::~AttachmentListView()
{
}
//-----------------------------------------------------------------------------
void AttachmentListView::contentsDragEnterEvent( TQDragEnterEvent* e )
{
if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
e->accept( true );
else
KListView::dragEnterEvent( e );
}
//-----------------------------------------------------------------------------
void AttachmentListView::contentsDragMoveEvent( TQDragMoveEvent* e )
{
if( e->provides( MailListDrag::format() ) || KURLDrag::canDecode( e ) )
e->accept( true );
else
KListView::dragMoveEvent( e );
}
//-----------------------------------------------------------------------------
void AttachmentListView::contentsDropEvent( TQDropEvent* e )
{
if( e->provides( MailListDrag::format() ) ) {
// Decode the list of serial numbers stored as the drag data
TQByteArray serNums;
MailListDrag::decode( e, serNums );
TQBuffer serNumBuffer( serNums );
serNumBuffer.open( IO_ReadOnly );
TQDataStream serNumStream( &serNumBuffer );
TQ_UINT32 serNum;
KMFolder *folder = 0;
int idx;
TQPtrList<KMMsgBase> messageList;
while( !serNumStream.atEnd() ) {
KMMsgBase *msgBase = 0;
serNumStream >> serNum;
KMMsgDict::instance()->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 {
KListView::dropEvent( e );
}
}
//-----------------------------------------------------------------------------
void AttachmentListView::keyPressEvent( TQKeyEvent * e )
{
if ( e->key() == Key_Delete ) {
emit attachmentDeleted();
}
}
/*virtual*/
void AttachmentListView::startDrag()
{
emit dragStarted();
}
} // namespace KMail
#include "attachmentlistview.moc"
|