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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
/*
* Copyright (C) 2004, Mart Kelder (mart.kde@hccnet.nl)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 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 USA
*/
#include "kio_delete.h"
#include "mailid.h"
#include "stringid.h"
#include "kio.h"
#include "kio_proto.h"
#include <kdebug.h>
#include <klocale.h>
#include <kurl.h>
#include <kio/global.h>
#include <kio/jobclasses.h>
#include <kio/scheduler.h>
#include <tqptrlist.h>
KIO_Delete::KIO_Delete( TQObject * tqparent, const char * name ) : TQObject( tqparent, name ),
_kio( 0 ),
_total( 0 ),
_jobs( 0 ),
_slave( 0 ),
_valid( true )
{
_jobs = new TQPtrList< KIO::Job >;
}
KIO_Delete::~KIO_Delete( )
{
disConnect( );
delete _jobs;
}
bool KIO_Delete::deleteMails( TQPtrList< const KornMailId > * ids, KKioDrop *drop )
{
KURL kurl = *drop->_kurl;
KIO::MetaData metadata = *drop->_metadata;
_kio = drop;
_valid = true;
//disConnect earlier operations
disConnect( );
if( _kio->_protocol->connectionBased( ) )
{
if( ! setupSlave( kurl, metadata, _kio->_protocol ) )
{
_valid = false;
return false;
}
}
_total = ids->count( );
for( const KornMailId * item = ids->first(); item; item = ids->next() )
deleteItem( item, kurl, metadata, _kio->_protocol );
if( _jobs->count() == 0 )
{
_kio->emitDeleteMailsReady( true );
disConnect( );
return true;
}
if( _kio->_protocol->commitDelete() )
commitDelete( kurl, metadata, _kio->_protocol );
_kio->emitDeleteMailsTotalSteps( _total );
return true;
}
void KIO_Delete::disConnect( )
{
_jobs->clear( );
if( _slave )
{
KIO::Scheduler::disconnectSlave( _slave );
_slave = 0;
}
}
bool KIO_Delete::setupSlave( KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol )
{
protocol->deleteMailConnectKURL( kurl, metadata );
if( kurl.port() == 0 )
kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
if( ! ( _slave = KIO::Scheduler::getConnectedSlave( kurl, metadata ) ) )
{
kdWarning() << i18n( "Could not get a connected slave; I cannot delete this way..." ) << endl;
_valid = false;
return false;
}
return true;
}
void KIO_Delete::deleteItem( const KornMailId *item, KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol )
{
KIO::Job* job = 0;
kurl = dynamic_cast<const KornStringId*>( item )->getId();
protocol->deleteMailKURL( kurl, metadata );
if( kurl.port() == 0 )
kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
if( protocol->deleteFunction() == KIO_Protocol::get )
{
job = KIO::get( kurl, true, false );
if( protocol->connectionBased() )
KIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< KIO::SimpleJob* >( job ) );
else
KIO::Scheduler::scheduleJob( dynamic_cast< KIO::SimpleJob* >( job ) );
}
else if( protocol->deleteFunction() == KIO_Protocol::del )
{
job = KIO::del( kurl, false, false );
}
else
return; //Unknown deleteFunction
connect( job, TQT_SIGNAL( result( KIO::Job* ) ), this, TQT_SLOT( slotResult( KIO::Job* ) ) );
job->addMetaData( metadata );
_jobs->append( dynamic_cast< KIO::Job* >( job ) );
}
/*
* Some protocols needs to a command to commit protocols.
*/
void KIO_Delete::commitDelete( KURL kurl, KIO::MetaData metadata, const KIO_Protocol *& protocol )
{
protocol->deleteCommitKURL( kurl, metadata );
if( kurl.port() == 0 )
kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
KIO::TransferJob *job = KIO::get( kurl, true, false );
job->addMetaData( metadata );
connect( job, TQT_SIGNAL( result( KIO::Job* ) ), this, TQT_SLOT( slotResult( KIO::Job* ) ) );
_jobs->append( dynamic_cast< KIO::Job* >( job ) );
if( protocol->connectionBased() )
KIO::Scheduler::assignJobToSlave( _slave, job );
else
KIO::Scheduler::scheduleJob( job );
_total++;
}
void KIO_Delete::canceled( )
{
disConnect( );
}
void KIO_Delete::slotResult( KIO::Job* job )
{
if( job->error() )
{
kdWarning() << i18n( "An error occurred when deleting email: %1." ).tqarg( job->errorString() ) << endl;
_valid = false;
}
_jobs->remove( job );
_kio->emitDeleteMailsProgress( _total - _jobs->count() );
if( _jobs->isEmpty() )
{
_kio->emitDeleteMailsReady( _valid );
disConnect();
}
}
#include "kio_delete.moc"
|