You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
4.8 KiB
202 lines
4.8 KiB
15 years ago
|
/*
|
||
|
* 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>
|
||
12 years ago
|
#include <tdeio/global.h>
|
||
|
#include <tdeio/jobclasses.h>
|
||
|
#include <tdeio/scheduler.h>
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqptrlist.h>
|
||
15 years ago
|
|
||
13 years ago
|
KIO_Delete::KIO_Delete( TQObject * parent, const char * name ) : TQObject( parent, name ),
|
||
15 years ago
|
_kio( 0 ),
|
||
|
_total( 0 ),
|
||
|
_jobs( 0 ),
|
||
|
_slave( 0 ),
|
||
|
_valid( true )
|
||
|
{
|
||
12 years ago
|
_jobs = new TQPtrList< TDEIO::Job >;
|
||
15 years ago
|
}
|
||
|
|
||
|
KIO_Delete::~KIO_Delete( )
|
||
|
{
|
||
|
disConnect( );
|
||
|
delete _jobs;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KIO_Delete::deleteMails( TQPtrList< const KornMailId > * ids, KKioDrop *drop )
|
||
15 years ago
|
{
|
||
|
KURL kurl = *drop->_kurl;
|
||
12 years ago
|
TDEIO::MetaData metadata = *drop->_metadata;
|
||
15 years ago
|
|
||
|
_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 )
|
||
|
{
|
||
12 years ago
|
TDEIO::Scheduler::disconnectSlave( _slave );
|
||
15 years ago
|
_slave = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
bool KIO_Delete::setupSlave( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol )
|
||
15 years ago
|
{
|
||
|
protocol->deleteMailConnectKURL( kurl, metadata );
|
||
|
|
||
|
if( kurl.port() == 0 )
|
||
|
kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
|
||
|
|
||
12 years ago
|
if( ! ( _slave = TDEIO::Scheduler::getConnectedSlave( kurl, metadata ) ) )
|
||
15 years ago
|
{
|
||
|
kdWarning() << i18n( "Could not get a connected slave; I cannot delete this way..." ) << endl;
|
||
|
_valid = false;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
void KIO_Delete::deleteItem( const KornMailId *item, KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEIO::Job* job = 0;
|
||
15 years ago
|
|
||
|
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 )
|
||
|
{
|
||
12 years ago
|
job = TDEIO::get( kurl, true, false );
|
||
15 years ago
|
|
||
|
if( protocol->connectionBased() )
|
||
12 years ago
|
TDEIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< TDEIO::SimpleJob* >( job ) );
|
||
15 years ago
|
else
|
||
12 years ago
|
TDEIO::Scheduler::scheduleJob( dynamic_cast< TDEIO::SimpleJob* >( job ) );
|
||
15 years ago
|
}
|
||
|
else if( protocol->deleteFunction() == KIO_Protocol::del )
|
||
|
{
|
||
12 years ago
|
job = TDEIO::del( kurl, false, false );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
return; //Unknown deleteFunction
|
||
|
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) );
|
||
15 years ago
|
|
||
|
job->addMetaData( metadata );
|
||
|
|
||
12 years ago
|
_jobs->append( dynamic_cast< TDEIO::Job* >( job ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
/*
|
||
|
* Some protocols needs to a command to commit protocols.
|
||
|
*/
|
||
12 years ago
|
void KIO_Delete::commitDelete( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol )
|
||
15 years ago
|
{
|
||
|
protocol->deleteCommitKURL( kurl, metadata );
|
||
|
|
||
|
if( kurl.port() == 0 )
|
||
|
kurl.setPort( protocol->defaultPort( _kio->_ssl ) );
|
||
|
|
||
12 years ago
|
TDEIO::TransferJob *job = TDEIO::get( kurl, true, false );
|
||
15 years ago
|
job->addMetaData( metadata );
|
||
12 years ago
|
connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) );
|
||
15 years ago
|
|
||
12 years ago
|
_jobs->append( dynamic_cast< TDEIO::Job* >( job ) );
|
||
15 years ago
|
|
||
|
if( protocol->connectionBased() )
|
||
12 years ago
|
TDEIO::Scheduler::assignJobToSlave( _slave, job );
|
||
15 years ago
|
else
|
||
12 years ago
|
TDEIO::Scheduler::scheduleJob( job );
|
||
15 years ago
|
|
||
|
_total++;
|
||
|
}
|
||
|
|
||
|
void KIO_Delete::canceled( )
|
||
|
{
|
||
|
disConnect( );
|
||
|
}
|
||
|
|
||
12 years ago
|
void KIO_Delete::slotResult( TDEIO::Job* job )
|
||
15 years ago
|
{
|
||
|
if( job->error() )
|
||
|
{
|
||
13 years ago
|
kdWarning() << i18n( "An error occurred when deleting email: %1." ).arg( job->errorString() ) << endl;
|
||
15 years ago
|
_valid = false;
|
||
|
}
|
||
|
|
||
|
_jobs->remove( job );
|
||
|
|
||
|
_kio->emitDeleteMailsProgress( _total - _jobs->count() );
|
||
|
|
||
|
if( _jobs->isEmpty() )
|
||
|
{
|
||
|
_kio->emitDeleteMailsReady( _valid );
|
||
|
disConnect();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "kio_delete.moc"
|