From c5bee2a602f3b6a9ca58c247df52b834ea50d0ed Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 27 Jan 2013 21:04:28 -0600 Subject: Rename kiobuffer and KHTML --- korn/kio_count.cpp | 330 ------------------------------------------ korn/kio_count.h | 82 ----------- korn/kio_delete.cpp | 201 ------------------------- korn/kio_delete.h | 70 --------- korn/kio_proto.cpp | 81 ----------- korn/kio_proto.h | 157 -------------------- korn/kio_read.cpp | 97 ------------- korn/kio_read.h | 61 -------- korn/kio_single_subject.cpp | 155 -------------------- korn/kio_single_subject.h | 68 --------- korn/kio_subjects.cpp | 176 ---------------------- korn/kio_subjects.h | 75 ---------- korn/tdeio_count.cpp | 330 ++++++++++++++++++++++++++++++++++++++++++ korn/tdeio_count.h | 82 +++++++++++ korn/tdeio_delete.cpp | 201 +++++++++++++++++++++++++ korn/tdeio_delete.h | 70 +++++++++ korn/tdeio_proto.cpp | 81 +++++++++++ korn/tdeio_proto.h | 157 ++++++++++++++++++++ korn/tdeio_read.cpp | 97 +++++++++++++ korn/tdeio_read.h | 61 ++++++++ korn/tdeio_single_subject.cpp | 155 ++++++++++++++++++++ korn/tdeio_single_subject.h | 68 +++++++++ korn/tdeio_subjects.cpp | 176 ++++++++++++++++++++++ korn/tdeio_subjects.h | 75 ++++++++++ 24 files changed, 1553 insertions(+), 1553 deletions(-) delete mode 100644 korn/kio_count.cpp delete mode 100644 korn/kio_count.h delete mode 100644 korn/kio_delete.cpp delete mode 100644 korn/kio_delete.h delete mode 100644 korn/kio_proto.cpp delete mode 100644 korn/kio_proto.h delete mode 100644 korn/kio_read.cpp delete mode 100644 korn/kio_read.h delete mode 100644 korn/kio_single_subject.cpp delete mode 100644 korn/kio_single_subject.h delete mode 100644 korn/kio_subjects.cpp delete mode 100644 korn/kio_subjects.h create mode 100644 korn/tdeio_count.cpp create mode 100644 korn/tdeio_count.h create mode 100644 korn/tdeio_delete.cpp create mode 100644 korn/tdeio_delete.h create mode 100644 korn/tdeio_proto.cpp create mode 100644 korn/tdeio_proto.h create mode 100644 korn/tdeio_read.cpp create mode 100644 korn/tdeio_read.h create mode 100644 korn/tdeio_single_subject.cpp create mode 100644 korn/tdeio_single_subject.h create mode 100644 korn/tdeio_subjects.cpp create mode 100644 korn/tdeio_subjects.h (limited to 'korn') diff --git a/korn/kio_count.cpp b/korn/kio_count.cpp deleted file mode 100644 index 1531a9b9..00000000 --- a/korn/kio_count.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* - * 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_count.h" - -#include "kio.h" -#include "kio_proto.h" -#include "kio_single_subject.h" -#include "mailsubject.h" -#include "sortedmailsubject.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -KIO_Count::KIO_Count( TQObject * parent, const char * name ) - : TQObject ( parent, name ), - _kurl( 0 ), - _metadata( 0 ), - _protocol( 0 ), - _valid( true ), - _new_mailurls( 0 ), - _subjects_pending( 0 ), - _total_new_messages( 0 ), - _popup_subjects( 0 ) -{ -} - -KIO_Count::~KIO_Count() -{ - // Delete copies of urls. - delete _kurl; - delete _metadata; -} - -void KIO_Count::count( KKioDrop *drop ) -{ - if( _new_mailurls ) - return; //A counting is pending, so no new one is started. - - delete _kurl; - delete _metadata; - _kio = drop; - - /* - * Saving current settings: all actions are asynchroon, so if someone - * use slow servers, settings could been changed before this class is - * finished with counten. To be able to track back te staring values; - * these are saved in the class. - */ - _kurl = new KURL( *_kio->_kurl ); - _metadata = new TDEIO::MetaData( *_kio->_metadata ); - _protocol = _kio->_protocol; - - KURL kurl = *_kurl; - TDEIO::MetaData metadata = *_metadata; - - // Serup a connection - if( _protocol->connectionBased( ) ) - { - _protocol->recheckConnectKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); - - if( ! ( _slave = TDEIO::Scheduler::getConnectedSlave( kurl, metadata ) ) ) //Forcing reload - { - kdWarning() << i18n( "Not able to open a kio slave for %1." ).arg( _protocol->configName() ) << endl; - _kio->emitShowPassivePopup( i18n( "Not able to open a kio slave for %1." ).arg( _protocol->configName() ) ); - _valid = false; - _kio->emitValidChanged(); - _slave = 0; - //delete _new_mailurls; _new_mailurls = 0; //No connection pending - return; - } - - connect( _slave, TQT_SIGNAL( error( int, const TQString& ) ), _kio, TQT_SLOT( slotConnectionError( int, const TQString& ) ) ); - connect( _slave, TQT_SIGNAL( warning( const TQString& ) ), _kio, TQT_SLOT( slotConnectionWarning( const TQString& ) ) ); - connect( _slave, TQT_SIGNAL( infoMessage( const TQString& ) ), _kio, TQT_SLOT( slotConnectionInfoMessage( const TQString& ) ) ); - - /* - * _protocol->recheckConnectKURL could have change kurl and metadata in order to have the right - * settings to connect. But some other functions assumed unmodified settings, - * so the settings are set back to his originals. - */ - kurl = *_kurl; - metadata = *_metadata; - } - else - { - _slave = 0; //Prevent disconnecting not-existing slave - } - - /* Blocking this function: no new counts can be started from now */ - _new_mailurls = new TQValueList< KKioDrop::FileInfo >; - - _protocol->recheckKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); - - //Making job to fetch file-list - - _job = TDEIO::listDir( kurl, false ); - _job->addMetaData( metadata ); - - connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); - connect( _job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), - this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); - - if( _protocol->connectionBased() ) - TDEIO::Scheduler::assignJobToSlave( _slave, _job ); - else - TDEIO::Scheduler::scheduleJob( _job ); -} - -void KIO_Count::stopActiveCount() -{ - if( !_new_mailurls ) - return; - - disconnect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); - disconnect( _job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), - this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); - - TDEIO::Scheduler::cancelJob( _job ); - - if( _slave ) - { - //Slave seems to be disconnected by canceling the last job of the slave - //TDEIO::Scheduler::disconnectSlave( _slave ); - _slave = 0; - } - - //Deletings settings - delete _kurl; _kurl = 0; - delete _metadata; _metadata = 0; - - delete _new_mailurls; _new_mailurls = 0; -} - -void KIO_Count::showPassive( const TQString& id ) -{ - KURL kurl = *_kio->_kurl; - TDEIO::MetaData metadata = *_kio->_metadata; - kurl = id; - //TDEIO::Slave *slave = 0; - - _kio->_protocol->readSubjectKURL( kurl, metadata ); - if( kurl.port() == 0 ) - kurl.setPort( _kio->_protocol->defaultPort( _kio->_ssl ) ); - - KIO_Single_Subject *subject = new KIO_Single_Subject( this, id.latin1(), kurl, metadata, _kio->_protocol, _slave, id, 0 ); - - _subjects_pending++; - - connect( subject, TQT_SIGNAL( readSubject( KornMailSubject* ) ), this, TQT_SLOT( addtoPassivePopup( KornMailSubject* ) ) ); - connect( subject, TQT_SIGNAL( finished( KIO_Single_Subject* ) ), this, TQT_SLOT( deleteSingleSubject( KIO_Single_Subject* ) ) ); -} - -void KIO_Count::disconnectSlave() -{ - if( _subjects_pending > 0 ) - return; //Still getting data - - if( !_protocol->connectionBased() ) - return; //Protocol doesn't have a connection - - if( !_slave ) - return; //Slave doens't exist - - //Disconnect slave - TDEIO::Scheduler::disconnectSlave( _slave ); - _slave = 0; - _protocol = 0; -} - -//This function is called when fetching is over -void KIO_Count::result( TDEIO::Job* job ) -{ - //job should be the latest job; elsewise: print an error. - if( job != _job ) - kdError() << i18n( "Got unknown job; something must be wrong..." ) << endl; - - //look of an error occurred. If there is, print the error. - //This could be very useful by resolving bugs. - if( job->error() ) - { - kdError() << i18n( "The next KIO-error occurred by counting: %1" ).arg( job->errorString() ) << endl; - _kio->emitShowPassivePopup( i18n( "The next KIO-error occurred by counting: %1" ).arg( job->errorString() ) ); - _valid = false; - _kio->emitValidChanged(); - } - - disconnect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); - disconnect( job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), - this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); - - disconnectSlave(); - - //Deletings settings - delete _kurl; _kurl = 0; - delete _metadata; _metadata = 0; - - if( _kio->_mailurls->count() != _new_mailurls->count() ) - { - *_kio->_mailurls = *_new_mailurls; - _kio->emitChanged(_kio->_mailurls->count()); - } - else - { - *_kio->_mailurls = *_new_mailurls; - } - delete _new_mailurls; _new_mailurls = 0; - - _valid = true; - _kio->emitValidChanged(); - _kio->emitRechecked(); -} - -//An file list is ready; now save it in _kio->_mailurls. -void KIO_Count::entries( TDEIO::Job* job, const TDEIO::UDSEntryList &list ) -{ - TQStringList old_list; - TDEIO::UDSEntryListConstIterator it1 ; - TDEIO::UDSEntry::ConstIterator it2 ; - TDEIO::MetaData metadata; - KURL kurl; - bool isFile; - - //job should be the latest job - if( job != _job ) - kdError() << i18n( "Got unknown job; something must be wrong..." ) << endl; - - for( TQValueListConstIterator it = _kio->_mailurls->begin(); it != _kio->_mailurls->end(); ++it ) - old_list.append( (*it).name ); - - for ( it1 = list.begin() ; it1 != list.end() ; it1++ ) - { - /* - * The list contains multiple objects. Each object could be a file. - * Settings about it are saved in this scope until it is added to the list. - */ - isFile=false; - KKioDrop::FileInfo fileinfo; - fileinfo.name = TQString(); - fileinfo.size = 0; - - for ( it2 = (*it1).begin() ; it2 != (*it1).end() ; it2++ ) - { - if( (*it2).m_uds == TDEIO::UDS_FILE_TYPE && - ((long)(*it2).m_long & S_IFREG ) ) - isFile=true; - else if( (*it2).m_uds == TDEIO::UDS_URL ) - fileinfo.name = (*it2).m_str; - else if( (*it2).m_uds == TDEIO::UDS_NAME ) - { //The file tdeioslave doesn't return UDS_URL. - kurl = *_kurl; - metadata = *_metadata; - _protocol->recheckKURL( kurl, metadata ); - kurl.setPath ( kurl.path() + '/' + (*it2).m_str ); - fileinfo.name = kurl.url(); - } - else if( (*it2).m_uds == TDEIO::UDS_SIZE ) - { - fileinfo.size = (*it2).m_long; - } - } - - //Add the entry. - if( ! fileinfo.name.isNull() && isFile ) - { - _new_mailurls->append( fileinfo ); - if( ! old_list.contains( fileinfo.name ) && _kio->passivePopup() ) - showPassive( fileinfo.name ); - } - } -} - -void KIO_Count::addtoPassivePopup( KornMailSubject* subject ) -{ - if( ! _popup_subjects ) - { - _popup_subjects = new SortedMailSubject; - _popup_subjects->setAutoDelete( true ); - } - - _popup_subjects->inSort( subject ); - if( _popup_subjects->count() > 5 ) - _popup_subjects->removeFirst(); //Overhead: subject is downloaded - - _subjects_pending--; - _total_new_messages++; - if( _subjects_pending == 0 ) - { - _kio->emitShowPassivePopup( dynamic_cast< TQPtrList* >( _popup_subjects ), _total_new_messages ); - delete _popup_subjects; _popup_subjects = 0; - _total_new_messages = 0; - - disconnectSlave(); - } -} - -void KIO_Count::deleteSingleSubject( KIO_Single_Subject* single_subject ) -{ - delete single_subject; -} - -#include "kio_count.moc" diff --git a/korn/kio_count.h b/korn/kio_count.h deleted file mode 100644 index e575864e..00000000 --- a/korn/kio_count.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIOCOUNT_H -#define MK_KIOCOUNT_H - -//This class count the number of message available. - -#include - -#include "kio.h" //Alsewise, no access to KKioDrop::FileInfo (needed in template) - -#include //FIXME: without this, moc-compiler fails. - -class KIO_Protocol; -class KIO_Single_Subject; -class KKioDrop; - -class KornMailSubject; -class SortedMailSubject; - -template class TQValueList; -namespace TDEIO { class Job; class ListJob; class MetaData; class Slave; } - -class KURL; - -class TQString; - -class KIO_Count : public TQObject -{ Q_OBJECT - -public: - KIO_Count( TQObject * parent = 0, const char * name = 0 ); - ~KIO_Count(); - - //This function starts counting - void count( KKioDrop* ); - - //This functions returns true of no error has occurred. - bool valid( ) { return _valid; } - - void stopActiveCount(); -private: - KKioDrop *_kio; - TDEIO::ListJob *_job; - TDEIO::Slave *_slave; - KURL *_kurl; - TDEIO::MetaData *_metadata; - const KIO_Protocol *_protocol; - bool _valid; - TQValueList *_new_mailurls; //entries can come with more function calls. - int _subjects_pending; - int _total_new_messages; - SortedMailSubject *_popup_subjects; -private: - void showPassive( const TQString& ); - void disconnectSlave(); - -private slots: - void result( TDEIO::Job* ); - void entries( TDEIO::Job*, const TDEIO::UDSEntryList &list ); - - void addtoPassivePopup( KornMailSubject* ); - void deleteSingleSubject( KIO_Single_Subject* ); -}; - -#endif diff --git a/korn/kio_delete.cpp b/korn/kio_delete.cpp deleted file mode 100644 index a73b0dd4..00000000 --- a/korn/kio_delete.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include - -#include - -KIO_Delete::KIO_Delete( TQObject * parent, const char * name ) : TQObject( parent, name ), - _kio( 0 ), - _total( 0 ), - _jobs( 0 ), - _slave( 0 ), - _valid( true ) -{ - _jobs = new TQPtrList< TDEIO::Job >; -} - -KIO_Delete::~KIO_Delete( ) -{ - disConnect( ); - delete _jobs; -} - -bool KIO_Delete::deleteMails( TQPtrList< const KornMailId > * ids, KKioDrop *drop ) -{ - KURL kurl = *drop->_kurl; - TDEIO::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 ) - { - TDEIO::Scheduler::disconnectSlave( _slave ); - _slave = 0; - } -} - -bool KIO_Delete::setupSlave( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) -{ - protocol->deleteMailConnectKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); - - if( ! ( _slave = TDEIO::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, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) -{ - TDEIO::Job* job = 0; - - kurl = dynamic_cast( item )->getId(); - - protocol->deleteMailKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); - - if( protocol->deleteFunction() == KIO_Protocol::get ) - { - job = TDEIO::get( kurl, true, false ); - - if( protocol->connectionBased() ) - TDEIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< TDEIO::SimpleJob* >( job ) ); - else - TDEIO::Scheduler::scheduleJob( dynamic_cast< TDEIO::SimpleJob* >( job ) ); - } - else if( protocol->deleteFunction() == KIO_Protocol::del ) - { - job = TDEIO::del( kurl, false, false ); - } - else - return; //Unknown deleteFunction - - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); - - job->addMetaData( metadata ); - - _jobs->append( dynamic_cast< TDEIO::Job* >( job ) ); -} - -/* - * Some protocols needs to a command to commit protocols. - */ -void KIO_Delete::commitDelete( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) -{ - protocol->deleteCommitKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); - - TDEIO::TransferJob *job = TDEIO::get( kurl, true, false ); - job->addMetaData( metadata ); - connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); - - _jobs->append( dynamic_cast< TDEIO::Job* >( job ) ); - - if( protocol->connectionBased() ) - TDEIO::Scheduler::assignJobToSlave( _slave, job ); - else - TDEIO::Scheduler::scheduleJob( job ); - - _total++; -} - -void KIO_Delete::canceled( ) -{ - disConnect( ); -} - -void KIO_Delete::slotResult( TDEIO::Job* job ) -{ - if( job->error() ) - { - kdWarning() << i18n( "An error occurred when deleting email: %1." ).arg( job->errorString() ) << endl; - _valid = false; - } - - _jobs->remove( job ); - - _kio->emitDeleteMailsProgress( _total - _jobs->count() ); - - if( _jobs->isEmpty() ) - { - _kio->emitDeleteMailsReady( _valid ); - disConnect(); - } -} - - -#include "kio_delete.moc" diff --git a/korn/kio_delete.h b/korn/kio_delete.h deleted file mode 100644 index c084a58d..00000000 --- a/korn/kio_delete.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIO_DELETE_H -#define MK_KIO_DELETE_H - -/* - * This class handles removing of selected messages. - * This class starts working when deleteMails() is called. - */ - -#include -class KKioDrop; -class KIO_Protocol; -class KornMailId; - -class KURL; -namespace TDEIO { class MetaData; class Job; class Slave; } - -template class TQPtrList; - -class KIO_Delete : public TQObject -{ Q_OBJECT - -public: - //constructors - KIO_Delete( TQObject * parent = 0, const char * name = 0 ); - ~KIO_Delete( ); - - //This function should be called if there are messages to be deleted. - bool deleteMails( TQPtrList< const KornMailId > *, KKioDrop* ); - - //This function should return false then and only then if an error occurred. - bool valid( ) { return _valid; } - -public slots: - //If this slot is called, the whole deletion is canceled. - void canceled( ); -private slots: - void slotResult( TDEIO::Job* ); - -private: - void disConnect( ); - bool setupSlave( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ); - void deleteItem( const KornMailId *item, KURL, TDEIO::MetaData, const KIO_Protocol *&); - void commitDelete( KURL, TDEIO::MetaData, const KIO_Protocol *& ); - - KKioDrop *_kio; - unsigned int _total; - TQPtrList< TDEIO::Job > *_jobs; - TDEIO::Slave *_slave; - bool _valid; -}; - -#endif //MK_KIO_DELETE_H diff --git a/korn/kio_proto.cpp b/korn/kio_proto.cpp deleted file mode 100644 index e63a7166..00000000 --- a/korn/kio_proto.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2005, 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_proto.h" - -#include -#include - -#include - -TQMap< TQString, TQString >* KIO_Protocol::createConfig( TDEConfigGroup * group, const TQString& password ) const -{ - TQMap< TQString, TQString > *result = new TQMap< TQString, TQString >; - - result->insert( "name", group->readEntry( "name", "" ) ); - result->insert( "server", group->readEntry( "server", "" ) ); - result->insert( "port", group->readEntry( "port", "" ) ); - result->insert( "username", group->readEntry( "username", "" ) ); - result->insert( "password", password ); - result->insert( "mailbox", group->readEntry( "mailbox", "" ) ); - result->insert( "savepassword", group->readEntry( "savepassword", "false" ) ); - result->insert( "ssl", group->readEntry( "ssl", "false" ) ); - result->insert( "metadata", group->readEntry( "metadata", "" ) ); - - return result; -} - -void KIO_Protocol::clearFields( TQMap *map, const KIO_Protocol::Fields fields ) const -{ - if( fields & server ) - map->insert( "server", "" ); - if( fields & port ) - map->insert( "port", "" ); - if( fields & username ) - map->insert( "username", "" ); - if( fields & password ) - map->insert( "password", "" ); - if( fields & mailbox ) - map->insert( "mailbox", "" ); - if( fields & save_password ) - map->insert( "savepassword", "" ); - if( fields & metadata ) - map->insert( "metadata", "" ); -} - -void KIO_Protocol::readEntries( TQMap< TQString, TQString >* map ) const -{ - TQMap< TQString, TQString> *metadata = new TQMap< TQString, TQString >; - - if( map->contains( "metadata" ) ) - { - TQStringList list = TQStringList::split( ",", *map->find( "metadata" ) ); - TQStringList::Iterator it; - for( it = list.begin(); it != list.end(); ++it ) - { - int split = (*it).find( '=' ); - - metadata->insert( (*it).left( split ), (*it).right( (*it).length() - split - 1 ) ); - } - } - - this->readEntries( map, metadata ); - - delete metadata; -} diff --git a/korn/kio_proto.h b/korn/kio_proto.h deleted file mode 100644 index 510e97d3..00000000 --- a/korn/kio_proto.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIO_PROTO_H -#define MK_KIO_PROTO_H - -/* - * KIO can handle multiple protocols. But some protocols have their own - * manipulations of KURL or MetaData , and some protocols could do more then other - * protocols. So, this class is the generic class of a class specified - * by a protocol. - */ - -class TQString; -#include -#include -#include -#include "protocol.h" - -#include "kio.h" - -class KIO_Protocol : public Protocol -{ -public: - /* - * Constuctor; empty - */ - KIO_Protocol() {} - - /* - * Destructor; empty too - */ - virtual ~KIO_Protocol() {} - - /* - * Public enumeration - */ - enum DeleteTypeEnum { get, del }; - /** - * This are the implementation of the Protocol-functions - */ - virtual const Protocol* getProtocol( TDEConfigGroup* ) const { return this; } - - virtual KMailDrop* createMaildrop( TDEConfigGroup* config ) const { return new KKioDrop( config ); } - - virtual TQMap< TQString, TQString >* createConfig( TDEConfigGroup *group, const TQString& password ) const; - - /* - * @return: the name of the kio_slave - */ - virtual TQString protocol( bool ) const { return "file"; } - - /* - * @return: the name of the protocol used by the configuration - */ - virtual TQString configName() const { return "not specified"; } - - virtual bool connectionBased() const { return false; } - - /* - * The next four functions return the [capebilities] of a protocol. - * fullMessage means that by downloaden, the whole message is downloaded. - * if it is false, only the headers should be downloaded. - */ - virtual bool canReadSubjects() const { return false; } - virtual bool canDeleteMail() const { return false; } - virtual bool canReadMail() const { return false; } - virtual bool fullMessage() const { return false; } - - /* - * The following lines are the options in the configuration; - * true means that an option is enabled; - * false means that the option is disabled. - */ - //virtual int fields() const { return server | port | username | password | mailbox; } - //virtual int urlFields() const { return no_fields; } - virtual unsigned short defaultPort( bool ) const { return 0; } - - /* - * This sets the string of such fields in Configuration - */ - virtual TQString serverName() const { return i18n( "Server:" ); } - virtual TQString portName() const { return i18n( "Port:" ); } - virtual TQString usernameName() const { return i18n( "Username:" ); } - virtual TQString mailboxName() const { return i18n( "Mailbox:" ); } - virtual TQString passwordName() const { return i18n( "Password:" ); } - virtual TQString savePasswordName() const { return i18n( "Save password" ); } - virtual TQString authName() const { return i18n( "Authentication:" ); } - - /* - * The next function returns the method of deleting: some protoocols - * like to delete files with TDEIO::get; other with TDEIO::del - */ - virtual DeleteTypeEnum deleteFunction() const { return del; } - - /* - * The next options are the input for the Authentication Combo, seperated by '|'. - * The name should be the same as the auth-metadata. - */ - virtual TQStringList authList() const { return TQStringList::split( '|', "Plain", false ); } - - /* - * The next functions are manipulations of an KURL. - * At some points in the code, a KURL is used. But sometimes, - * these have to had a little retouch. That is possible with these function. - * - * For example, by imap, by default, the whole message is downloaded and marked as reed. - * By changing an option to the KURL path, this can be prevented. - * - * The most functions are recognized by name. - * commitDelete return true if a protocol has to confirm a deletion. - * It will be called after marking the messages for deletion. - * deleteCommitKURL is the KURL manipulator; the KURL is as in the settings. - * That KURL isn't retouch by deleteMailKURL. - */ - virtual void recheckConnectKURL( KURL &, TDEIO::MetaData & ) const { } - virtual void recheckKURL ( KURL &, TDEIO::MetaData & ) const { }; - virtual void readSubjectConnectKURL ( KURL & kurl, TDEIO::MetaData & ) const { kurl.setPath( "" ); } - virtual void readSubjectKURL ( KURL &, TDEIO::MetaData & ) const { } //For editing a kurl (adding extra options) - virtual void deleteMailConnectKURL( KURL & kurl, TDEIO::MetaData & ) const { kurl.setPath( "" ); } - virtual void deleteMailKURL ( KURL &, TDEIO::MetaData & ) const { } - virtual bool commitDelete() const { return false; } - virtual void deleteCommitKURL( KURL &, TDEIO::MetaData & ) const { } - virtual void readMailKURL ( KURL &, TDEIO::MetaData & ) const { } - - - virtual const KIO_Protocol* getKIOProtocol() const { return this; } - - virtual void readEntries( TQMap< TQString, TQString >* ) const; - virtual void readEntries( TQMap< TQString, TQString >*, TQMap< TQString, TQString >* ) const = 0; - -protected: - /* - * This enumeration is used when returning the capebilitys of a protocol - */ - enum Fields { no_fields = 0, server = 1, port = 2, username = 4, password = 8, - mailbox = 16, save_password = 32, metadata = 64 }; - - void clearFields( TQMap< TQString, TQString > *map, const Fields fields ) const; -}; - -#endif //MK_KIO_PROTO_H diff --git a/korn/kio_read.cpp b/korn/kio_read.cpp deleted file mode 100644 index f98669d8..00000000 --- a/korn/kio_read.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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_read.h" - -#include "kio.h" -#include "kio_proto.h" -#include "mailid.h" -#include "stringid.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -KIO_Read::KIO_Read( TQObject * parent, const char * name ) - : TQObject( parent, name ), - _job( 0 ), - _message( 0 ) -{ - _message = new TQString; -} - -KIO_Read::~KIO_Read() -{ - delete _message; - delete _job; -} - -void KIO_Read::readMail( const KornMailId *& mailid, KKioDrop* drop ) -{ - _kio = drop; - KURL kurl = *_kio->_kurl; - TDEIO::MetaData metadata = *_kio->_metadata; - - kurl = dynamic_cast(mailid)->getId( ); - - _kio->_protocol->readMailKURL( kurl, metadata ); - - _job = TDEIO::get( kurl, false, false ); - _job->addMetaData( metadata ); - - connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); - connect( _job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), this, TQT_SLOT( slotData( TDEIO::Job*, const TQByteArray & ) ) ); -} - -void KIO_Read::canceled( ) -{ - if( _job ) - delete _job; - _job = 0; -} - -void KIO_Read::slotResult( TDEIO::Job* job ) -{ - if( job != _job ) - kdWarning() << i18n( "Unknown job returned; I will try if this one will do... " ) << endl; - - if( job->error() ) - kdWarning() << i18n( "An error occurred when fetching the requested email: %1." ).arg( job->errorString() ) << endl; - - _kio->emitReadMailReady( _message ); - - *_message = ""; - _job = 0; -} - -void KIO_Read::slotData( TDEIO::Job* job, const TQByteArray & data ) -{ - if( job != _job ) - kdWarning() << i18n( "Unknown job returned; I will try if this one will do... " ) << endl; - - if( !data.isEmpty() ) - _message->append( data ); -} - -#include "kio_read.moc" diff --git a/korn/kio_read.h b/korn/kio_read.h deleted file mode 100644 index 3b1ddec8..00000000 --- a/korn/kio_read.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIO_READ_H -#define MK_KIO_READ_H - -//This class should be used if someone wants to read the Full Message - -#include - -class KKioDrop; -class KornMailId; - -class KURL; -namespace TDEIO { class MetaData; class Job; } -class KIO_Protocol; - -class TQString; - -class KIO_Read : public TQObject -{ Q_OBJECT - -public: - KIO_Read( TQObject * parent = 0, const char * name = 0 ); - ~KIO_Read(); - -public slots: - //This is the function which makes the nessesairy slaves for reading a message - void readMail( const KornMailId *&, KKioDrop* ); - //This function should be called if the user presses canceled. - void canceled(); -private: - KKioDrop *_kio; - TDEIO::Job *_job; - TQString *_message; - -signals: - //This signal is emitted when the whole message is read; the message got passed as TQString* - void ready( TQString* ); - -private slots: - void slotResult( TDEIO::Job* ); - void slotData( TDEIO::Job*, const TQByteArray& ); -}; - -#endif //MK_KIO_READ_H diff --git a/korn/kio_single_subject.cpp b/korn/kio_single_subject.cpp deleted file mode 100644 index 0c20b1ab..00000000 --- a/korn/kio_single_subject.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - * 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_single_subject.h" - -#include "mailsubject.h" -#include "kio_proto.h" -#include "stringid.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -KIO_Single_Subject::KIO_Single_Subject( TQObject * parent, const char * name, - KURL &kurl, TDEIO::MetaData &metadata, const KIO_Protocol * protocol, TDEIO::Slave *& slave, - const TQString &url, const long size ) - : TQObject( parent, name ) -{ - _kurl = new KURL( kurl ); - _metadata = new TDEIO::MetaData( metadata ); - _protocol = protocol; - _name = new TQString( url ); - _size = size; - _message = new TQString; - - init( slave ); -} - -KIO_Single_Subject::~KIO_Single_Subject( ) -{ - if( _job ) - TDEIO::Scheduler::cancelJob( _job ); - delete _kurl; - delete _metadata; - delete _name; - delete _message; -} - -void KIO_Single_Subject::init( TDEIO::Slave *& slave) -{ - _job = TDEIO::get( *_kurl, false, false ); - _job->addMetaData( *_metadata ); - - connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); - connect( _job, TQT_SIGNAL( data (TDEIO::Job *, const TQByteArray &) ), - this, TQT_SLOT( slotData(TDEIO::Job *, const TQByteArray &) ) ); - - if( _protocol->connectionBased( ) && slave ) - TDEIO::Scheduler::assignJobToSlave( slave , _job ); - else - TDEIO::Scheduler::scheduleJob( _job ); - -} - -void KIO_Single_Subject::parseMail( TQString * message, KornMailSubject *subject, bool fullMessage ) -{ - TQTextStream stream( message, IO_ReadOnly ); - TQString line; - TQRegExp rx_sender( "^[fF]rom: " ); //Ex: From: ... - TQRegExp rx_sender_has_name1( "^[fF]rom:\\s*(\\w+[\\w\\s]*)\\<" ); //Ex: From: A name - TQRegExp rx_sender_has_name2( "^[fF]rom:\\s*\\\"\\s*(\\w+[\\w\\s]*)\\\""); //Ex: From: "A name" - TQRegExp rx_subject( "^[sS]ubject: " ); //Ex: Subject: ... - TQRegExp rx_date ( "^[dD]ate: "); - bool inheader = true; - int fieldnumber = 0; - - while ( ! stream.atEnd() ) - { - line = stream.readLine(); - if( line.isEmpty() && fieldnumber >= 2 ) - inheader = false; - - if( inheader ) - { - if( rx_sender.search( line ) == 0 ) - { - if( rx_sender_has_name1.search( line ) == 0 ) - subject->setSender( rx_sender_has_name1.cap( 1 ) ); - else if(rx_sender_has_name2.search( line ) == 0) - subject->setSender( rx_sender_has_name2.cap( 1 ) ); - else - subject->setSender( line.remove( rx_sender ) ); - ++fieldnumber; - } - else if( rx_subject.search( line ) == 0 ) - { - subject->setSubject( line.remove( rx_subject ) ); - ++fieldnumber; - } - else if( rx_date.search( line ) == 0 ) - { - subject->setDate( KRFCDate::parseDate( line.right( line.length() - 6 ) ) ); - ++fieldnumber; - } - } - } - - subject->setHeader( *message, fullMessage ); -} - -void KIO_Single_Subject::slotData( TDEIO::Job* job, const TQByteArray& data ) -{ - if( job != _job ) - kdWarning() << i18n( "Got invalid job; something strange happened?" ) << endl; - if( !data.isEmpty() ) - _message->append( data ); -} - -//TDEIO::Scheduler::disconnectSlave missing if connection stops -void KIO_Single_Subject::slotResult( TDEIO::Job *job ) -{ - if( job != _job ) - kdWarning() << i18n( "Got invalid job; something strange happened?" ) << endl; - - if( job->error() ) - { - kdWarning() << i18n( "Error when fetching %1: %2" ).arg( *_name ).arg( job->errorString() ) << endl; - } else { - KornMailSubject * mailSubject = new KornMailSubject( new KornStringId( *_name ), 0 ); - parseMail( _message, mailSubject, _protocol->fullMessage() ); - mailSubject->decodeHeaders(); - mailSubject->setSize( _size ); - emit readSubject( mailSubject ); - } - - _job = 0; - - emit finished( this ); -} - -#include "kio_single_subject.moc" diff --git a/korn/kio_single_subject.h b/korn/kio_single_subject.h deleted file mode 100644 index 9aac8baa..00000000 --- a/korn/kio_single_subject.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIO_SINGEL_SUBJECT_H -#define MK_KIO_SINGEL_SUBJECT_H - -//This function reads a single subject - -#include -#include - -class KornMailSubject; - -class KURL; -namespace TDEIO { class MetaData; class Job; class TransferJob; class Slave; } -class KIO_Protocol; - -class TQString; - -class KIO_Single_Subject : public TQObject -{ Q_OBJECT - -public: - KIO_Single_Subject( TQObject * parent, const char * name, KURL &, TDEIO::MetaData &, const KIO_Protocol *, - TDEIO::Slave *&, const TQString &, const long ); - ~KIO_Single_Subject( ); - - //This functions try's te parse EMail; data, sender names and so on... - static void parseMail( TQString * message, KornMailSubject *subject, bool ); - -private: - TQString *_message; - TQString *_name; - KURL *_kurl; - const KIO_Protocol *_protocol; - TDEIO::MetaData *_metadata; - TDEIO::TransferJob* _job; - long _size; - - void init( TDEIO::Slave*& ); - -private slots: - void slotResult( TDEIO::Job* ); - void slotData( TDEIO::Job*, const TQByteArray& ); - -signals: - //This signal is emitted if the headers are read and put into a KornMailSubject* - void readSubject( KornMailSubject* ); - //This signal is emitted if this class could be destroyed. - void finished( KIO_Single_Subject* ); -}; - -#endif diff --git a/korn/kio_subjects.cpp b/korn/kio_subjects.cpp deleted file mode 100644 index f40a86f6..00000000 --- a/korn/kio_subjects.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - * 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_subjects.h" - -#include "kio.h" -#include "kio_single_subject.h" -#include "kio_proto.h" -#include "mailsubject.h" - -#include -#include -#include - -#include -#include -#include - -KIO_Subjects::KIO_Subjects( TQObject * parent, const char * name ) - : TQObject( parent, name ), - _protocol( 0 ), - _slave( 0 ), - _valid( true ) -{ - _jobs = new TQPtrList; - _kurl = new KURL; - _metadata = new TDEIO::MetaData; - - _jobs->setAutoDelete( true ); -} - -KIO_Subjects::~KIO_Subjects( ) -{ - delete _jobs; - delete _kurl; - delete _metadata; - _protocol = 0; -} - -void KIO_Subjects::doReadSubjects( KKioDrop *drop ) -{ - TQValueList::ConstIterator it; - TQValueList::ConstIterator end_it = drop->_mailurls->end(); - - _kio = drop; - _protocol = _kio->_protocol; - *_kurl = *_kio->_kurl; - *_metadata = *_kio->_metadata; - - if( _jobs->count() > 0 ) - kdWarning() << i18n( "Already a slave pending." ) << endl; - - _jobs->clear( ); - - //Open connection - getConnection( ); - - //Open jobs for easy item in the list - for( it = _kio->_mailurls->begin(); it != end_it; it++ ) - startJob( (*it).name, (*it).size ); - - //close connection for trivial situations (empty list) - disConnect( true ); - - //passing number of subjects for progress bar. - _kio->emitReadSubjectsTotalSteps( _jobs->count() ); -} - -void KIO_Subjects::getConnection( ) -{ - KURL kurl = *_kurl; - TDEIO::MetaData metadata = *_metadata; - - if( _slave ) - { - TDEIO::Scheduler::disconnectSlave( _slave ); - _slave = 0; - } - - if( _protocol->connectionBased( ) ) - { - _protocol->readSubjectConnectKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); - - if( ! ( _slave = TDEIO::Scheduler::getConnectedSlave( kurl, metadata ) ) ) - { - kdWarning() << i18n( "Not able to open a kio-slave for %1." ).arg( _protocol->configName() ); - _kio->emitShowPassivePopup( i18n( "Not able to open a kio-slave for %1." ).arg( _protocol->configName() ) ); - _valid = false; - _kio->emitValidChanged(); - _slave = 0; - _kio->emitReadSubjectsReady( false ); - return; - } - } -} - -void KIO_Subjects::startJob( const TQString &name, const long size ) -{ - KURL kurl = *_kurl; - TDEIO::MetaData metadata = *_metadata; - KIO_Single_Subject *subject; - - kurl = name; - - _protocol->readSubjectKURL( kurl, metadata ); - - if( kurl.port() == 0 ) - kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); - - subject = new KIO_Single_Subject( this, name.latin1(), kurl, metadata, _protocol, _slave, name, size ); - - connect( subject, TQT_SIGNAL( readSubject( KornMailSubject* ) ), this, TQT_SLOT( slotReadSubject( KornMailSubject* ) ) ); - connect( subject, TQT_SIGNAL( finished( KIO_Single_Subject* ) ), this, TQT_SLOT( slotFinished( KIO_Single_Subject* ) ) ); - - _jobs->append( subject ); -} - -void KIO_Subjects::disConnect( bool result ) -{ - if( _jobs->isEmpty() ) - { - if( _slave ) - { - TDEIO::Scheduler::disconnectSlave( _slave ); - _slave = 0; - } - _kio->emitReadSubjectsReady( result ); - } -} - -void KIO_Subjects::cancelled( ) -{ - _jobs->clear(); - //_slave died in cancelJob with is by called from the destructor of KIO_Single_Subject, - //withs is by called by _jobs->clear because autoRemove equals true. - _slave = 0; - disConnect( false ); -} - -void KIO_Subjects::slotReadSubject( KornMailSubject* subject ) -{ - _valid = true; - _kio->emitValidChanged(); - subject->setMailDrop( _kio ); - _kio->emitReadSubjectsRead( subject ); -} - -void KIO_Subjects::slotFinished( KIO_Single_Subject* item ) -{ - //Remove sender.... I didn't know of the computer gonna like me, but it seems he does :) - _jobs->remove( item ); - - _kio->emitReadSubjectsProgress( _jobs->count( ) ); - - disConnect( true ); //Only works when all jobs are finished. -} - -#include "kio_subjects.moc" diff --git a/korn/kio_subjects.h b/korn/kio_subjects.h deleted file mode 100644 index 018369de..00000000 --- a/korn/kio_subjects.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 - */ - -#ifndef MK_KIO_SUBJECTS_H -#define MK_KIO_SUBJECTS_H - -//This class calls other class to read all the subjects - -#include -class KKioDrop; -class KIO_Single_Subject; -class KIO_Protocol; -class KornMailSubject; - -namespace TDEIO { class MetaData; class Slave; } -class KURL; - -template class TQPtrList; -class TQString; -template class TQValueList; - -class KIO_Subjects : public TQObject -{ Q_OBJECT - -public: - KIO_Subjects( TQObject * parent, const char * name ); - ~KIO_Subjects( ); - - //This function let it start fetching headers. - void doReadSubjects( KKioDrop* ); - - //This function should return true then and only then of no error occurred. - bool valid( ) { return _valid; } - -private: - KKioDrop *_kio; - KURL *_kurl; - TDEIO::MetaData *_metadata; - const KIO_Protocol *_protocol; - TQPtrList *_jobs; - TDEIO::Slave *_slave; - bool _valid; - - //Opens a connection. - void getConnection( ); - //Start a job; the job itself is executed in KIO_Single_Subject - void startJob( const TQString&, const long ); - //Disconnect the connection - void disConnect( bool ); - -public slots: - //This function called the fetching of headers. - void cancelled( ); - -private slots: - void slotReadSubject( KornMailSubject* ); - void slotFinished( KIO_Single_Subject* ); -}; - -#endif diff --git a/korn/tdeio_count.cpp b/korn/tdeio_count.cpp new file mode 100644 index 00000000..1531a9b9 --- /dev/null +++ b/korn/tdeio_count.cpp @@ -0,0 +1,330 @@ +/* + * 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_count.h" + +#include "kio.h" +#include "kio_proto.h" +#include "kio_single_subject.h" +#include "mailsubject.h" +#include "sortedmailsubject.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +KIO_Count::KIO_Count( TQObject * parent, const char * name ) + : TQObject ( parent, name ), + _kurl( 0 ), + _metadata( 0 ), + _protocol( 0 ), + _valid( true ), + _new_mailurls( 0 ), + _subjects_pending( 0 ), + _total_new_messages( 0 ), + _popup_subjects( 0 ) +{ +} + +KIO_Count::~KIO_Count() +{ + // Delete copies of urls. + delete _kurl; + delete _metadata; +} + +void KIO_Count::count( KKioDrop *drop ) +{ + if( _new_mailurls ) + return; //A counting is pending, so no new one is started. + + delete _kurl; + delete _metadata; + _kio = drop; + + /* + * Saving current settings: all actions are asynchroon, so if someone + * use slow servers, settings could been changed before this class is + * finished with counten. To be able to track back te staring values; + * these are saved in the class. + */ + _kurl = new KURL( *_kio->_kurl ); + _metadata = new TDEIO::MetaData( *_kio->_metadata ); + _protocol = _kio->_protocol; + + KURL kurl = *_kurl; + TDEIO::MetaData metadata = *_metadata; + + // Serup a connection + if( _protocol->connectionBased( ) ) + { + _protocol->recheckConnectKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); + + if( ! ( _slave = TDEIO::Scheduler::getConnectedSlave( kurl, metadata ) ) ) //Forcing reload + { + kdWarning() << i18n( "Not able to open a kio slave for %1." ).arg( _protocol->configName() ) << endl; + _kio->emitShowPassivePopup( i18n( "Not able to open a kio slave for %1." ).arg( _protocol->configName() ) ); + _valid = false; + _kio->emitValidChanged(); + _slave = 0; + //delete _new_mailurls; _new_mailurls = 0; //No connection pending + return; + } + + connect( _slave, TQT_SIGNAL( error( int, const TQString& ) ), _kio, TQT_SLOT( slotConnectionError( int, const TQString& ) ) ); + connect( _slave, TQT_SIGNAL( warning( const TQString& ) ), _kio, TQT_SLOT( slotConnectionWarning( const TQString& ) ) ); + connect( _slave, TQT_SIGNAL( infoMessage( const TQString& ) ), _kio, TQT_SLOT( slotConnectionInfoMessage( const TQString& ) ) ); + + /* + * _protocol->recheckConnectKURL could have change kurl and metadata in order to have the right + * settings to connect. But some other functions assumed unmodified settings, + * so the settings are set back to his originals. + */ + kurl = *_kurl; + metadata = *_metadata; + } + else + { + _slave = 0; //Prevent disconnecting not-existing slave + } + + /* Blocking this function: no new counts can be started from now */ + _new_mailurls = new TQValueList< KKioDrop::FileInfo >; + + _protocol->recheckKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); + + //Making job to fetch file-list + + _job = TDEIO::listDir( kurl, false ); + _job->addMetaData( metadata ); + + connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); + connect( _job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), + this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); + + if( _protocol->connectionBased() ) + TDEIO::Scheduler::assignJobToSlave( _slave, _job ); + else + TDEIO::Scheduler::scheduleJob( _job ); +} + +void KIO_Count::stopActiveCount() +{ + if( !_new_mailurls ) + return; + + disconnect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); + disconnect( _job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), + this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); + + TDEIO::Scheduler::cancelJob( _job ); + + if( _slave ) + { + //Slave seems to be disconnected by canceling the last job of the slave + //TDEIO::Scheduler::disconnectSlave( _slave ); + _slave = 0; + } + + //Deletings settings + delete _kurl; _kurl = 0; + delete _metadata; _metadata = 0; + + delete _new_mailurls; _new_mailurls = 0; +} + +void KIO_Count::showPassive( const TQString& id ) +{ + KURL kurl = *_kio->_kurl; + TDEIO::MetaData metadata = *_kio->_metadata; + kurl = id; + //TDEIO::Slave *slave = 0; + + _kio->_protocol->readSubjectKURL( kurl, metadata ); + if( kurl.port() == 0 ) + kurl.setPort( _kio->_protocol->defaultPort( _kio->_ssl ) ); + + KIO_Single_Subject *subject = new KIO_Single_Subject( this, id.latin1(), kurl, metadata, _kio->_protocol, _slave, id, 0 ); + + _subjects_pending++; + + connect( subject, TQT_SIGNAL( readSubject( KornMailSubject* ) ), this, TQT_SLOT( addtoPassivePopup( KornMailSubject* ) ) ); + connect( subject, TQT_SIGNAL( finished( KIO_Single_Subject* ) ), this, TQT_SLOT( deleteSingleSubject( KIO_Single_Subject* ) ) ); +} + +void KIO_Count::disconnectSlave() +{ + if( _subjects_pending > 0 ) + return; //Still getting data + + if( !_protocol->connectionBased() ) + return; //Protocol doesn't have a connection + + if( !_slave ) + return; //Slave doens't exist + + //Disconnect slave + TDEIO::Scheduler::disconnectSlave( _slave ); + _slave = 0; + _protocol = 0; +} + +//This function is called when fetching is over +void KIO_Count::result( TDEIO::Job* job ) +{ + //job should be the latest job; elsewise: print an error. + if( job != _job ) + kdError() << i18n( "Got unknown job; something must be wrong..." ) << endl; + + //look of an error occurred. If there is, print the error. + //This could be very useful by resolving bugs. + if( job->error() ) + { + kdError() << i18n( "The next KIO-error occurred by counting: %1" ).arg( job->errorString() ) << endl; + _kio->emitShowPassivePopup( i18n( "The next KIO-error occurred by counting: %1" ).arg( job->errorString() ) ); + _valid = false; + _kio->emitValidChanged(); + } + + disconnect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( result( TDEIO::Job* ) ) ); + disconnect( job, TQT_SIGNAL( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ), + this, TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) ); + + disconnectSlave(); + + //Deletings settings + delete _kurl; _kurl = 0; + delete _metadata; _metadata = 0; + + if( _kio->_mailurls->count() != _new_mailurls->count() ) + { + *_kio->_mailurls = *_new_mailurls; + _kio->emitChanged(_kio->_mailurls->count()); + } + else + { + *_kio->_mailurls = *_new_mailurls; + } + delete _new_mailurls; _new_mailurls = 0; + + _valid = true; + _kio->emitValidChanged(); + _kio->emitRechecked(); +} + +//An file list is ready; now save it in _kio->_mailurls. +void KIO_Count::entries( TDEIO::Job* job, const TDEIO::UDSEntryList &list ) +{ + TQStringList old_list; + TDEIO::UDSEntryListConstIterator it1 ; + TDEIO::UDSEntry::ConstIterator it2 ; + TDEIO::MetaData metadata; + KURL kurl; + bool isFile; + + //job should be the latest job + if( job != _job ) + kdError() << i18n( "Got unknown job; something must be wrong..." ) << endl; + + for( TQValueListConstIterator it = _kio->_mailurls->begin(); it != _kio->_mailurls->end(); ++it ) + old_list.append( (*it).name ); + + for ( it1 = list.begin() ; it1 != list.end() ; it1++ ) + { + /* + * The list contains multiple objects. Each object could be a file. + * Settings about it are saved in this scope until it is added to the list. + */ + isFile=false; + KKioDrop::FileInfo fileinfo; + fileinfo.name = TQString(); + fileinfo.size = 0; + + for ( it2 = (*it1).begin() ; it2 != (*it1).end() ; it2++ ) + { + if( (*it2).m_uds == TDEIO::UDS_FILE_TYPE && + ((long)(*it2).m_long & S_IFREG ) ) + isFile=true; + else if( (*it2).m_uds == TDEIO::UDS_URL ) + fileinfo.name = (*it2).m_str; + else if( (*it2).m_uds == TDEIO::UDS_NAME ) + { //The file tdeioslave doesn't return UDS_URL. + kurl = *_kurl; + metadata = *_metadata; + _protocol->recheckKURL( kurl, metadata ); + kurl.setPath ( kurl.path() + '/' + (*it2).m_str ); + fileinfo.name = kurl.url(); + } + else if( (*it2).m_uds == TDEIO::UDS_SIZE ) + { + fileinfo.size = (*it2).m_long; + } + } + + //Add the entry. + if( ! fileinfo.name.isNull() && isFile ) + { + _new_mailurls->append( fileinfo ); + if( ! old_list.contains( fileinfo.name ) && _kio->passivePopup() ) + showPassive( fileinfo.name ); + } + } +} + +void KIO_Count::addtoPassivePopup( KornMailSubject* subject ) +{ + if( ! _popup_subjects ) + { + _popup_subjects = new SortedMailSubject; + _popup_subjects->setAutoDelete( true ); + } + + _popup_subjects->inSort( subject ); + if( _popup_subjects->count() > 5 ) + _popup_subjects->removeFirst(); //Overhead: subject is downloaded + + _subjects_pending--; + _total_new_messages++; + if( _subjects_pending == 0 ) + { + _kio->emitShowPassivePopup( dynamic_cast< TQPtrList* >( _popup_subjects ), _total_new_messages ); + delete _popup_subjects; _popup_subjects = 0; + _total_new_messages = 0; + + disconnectSlave(); + } +} + +void KIO_Count::deleteSingleSubject( KIO_Single_Subject* single_subject ) +{ + delete single_subject; +} + +#include "kio_count.moc" diff --git a/korn/tdeio_count.h b/korn/tdeio_count.h new file mode 100644 index 00000000..e575864e --- /dev/null +++ b/korn/tdeio_count.h @@ -0,0 +1,82 @@ +/* + * 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 + */ + +#ifndef MK_KIOCOUNT_H +#define MK_KIOCOUNT_H + +//This class count the number of message available. + +#include + +#include "kio.h" //Alsewise, no access to KKioDrop::FileInfo (needed in template) + +#include //FIXME: without this, moc-compiler fails. + +class KIO_Protocol; +class KIO_Single_Subject; +class KKioDrop; + +class KornMailSubject; +class SortedMailSubject; + +template class TQValueList; +namespace TDEIO { class Job; class ListJob; class MetaData; class Slave; } + +class KURL; + +class TQString; + +class KIO_Count : public TQObject +{ Q_OBJECT + +public: + KIO_Count( TQObject * parent = 0, const char * name = 0 ); + ~KIO_Count(); + + //This function starts counting + void count( KKioDrop* ); + + //This functions returns true of no error has occurred. + bool valid( ) { return _valid; } + + void stopActiveCount(); +private: + KKioDrop *_kio; + TDEIO::ListJob *_job; + TDEIO::Slave *_slave; + KURL *_kurl; + TDEIO::MetaData *_metadata; + const KIO_Protocol *_protocol; + bool _valid; + TQValueList *_new_mailurls; //entries can come with more function calls. + int _subjects_pending; + int _total_new_messages; + SortedMailSubject *_popup_subjects; +private: + void showPassive( const TQString& ); + void disconnectSlave(); + +private slots: + void result( TDEIO::Job* ); + void entries( TDEIO::Job*, const TDEIO::UDSEntryList &list ); + + void addtoPassivePopup( KornMailSubject* ); + void deleteSingleSubject( KIO_Single_Subject* ); +}; + +#endif diff --git a/korn/tdeio_delete.cpp b/korn/tdeio_delete.cpp new file mode 100644 index 00000000..a73b0dd4 --- /dev/null +++ b/korn/tdeio_delete.cpp @@ -0,0 +1,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 +#include +#include +#include +#include +#include + +#include + +KIO_Delete::KIO_Delete( TQObject * parent, const char * name ) : TQObject( parent, name ), + _kio( 0 ), + _total( 0 ), + _jobs( 0 ), + _slave( 0 ), + _valid( true ) +{ + _jobs = new TQPtrList< TDEIO::Job >; +} + +KIO_Delete::~KIO_Delete( ) +{ + disConnect( ); + delete _jobs; +} + +bool KIO_Delete::deleteMails( TQPtrList< const KornMailId > * ids, KKioDrop *drop ) +{ + KURL kurl = *drop->_kurl; + TDEIO::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 ) + { + TDEIO::Scheduler::disconnectSlave( _slave ); + _slave = 0; + } +} + +bool KIO_Delete::setupSlave( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) +{ + protocol->deleteMailConnectKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); + + if( ! ( _slave = TDEIO::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, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) +{ + TDEIO::Job* job = 0; + + kurl = dynamic_cast( item )->getId(); + + protocol->deleteMailKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); + + if( protocol->deleteFunction() == KIO_Protocol::get ) + { + job = TDEIO::get( kurl, true, false ); + + if( protocol->connectionBased() ) + TDEIO::Scheduler::assignJobToSlave( _slave, dynamic_cast< TDEIO::SimpleJob* >( job ) ); + else + TDEIO::Scheduler::scheduleJob( dynamic_cast< TDEIO::SimpleJob* >( job ) ); + } + else if( protocol->deleteFunction() == KIO_Protocol::del ) + { + job = TDEIO::del( kurl, false, false ); + } + else + return; //Unknown deleteFunction + + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); + + job->addMetaData( metadata ); + + _jobs->append( dynamic_cast< TDEIO::Job* >( job ) ); +} + +/* + * Some protocols needs to a command to commit protocols. + */ +void KIO_Delete::commitDelete( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ) +{ + protocol->deleteCommitKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( protocol->defaultPort( _kio->_ssl ) ); + + TDEIO::TransferJob *job = TDEIO::get( kurl, true, false ); + job->addMetaData( metadata ); + connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); + + _jobs->append( dynamic_cast< TDEIO::Job* >( job ) ); + + if( protocol->connectionBased() ) + TDEIO::Scheduler::assignJobToSlave( _slave, job ); + else + TDEIO::Scheduler::scheduleJob( job ); + + _total++; +} + +void KIO_Delete::canceled( ) +{ + disConnect( ); +} + +void KIO_Delete::slotResult( TDEIO::Job* job ) +{ + if( job->error() ) + { + kdWarning() << i18n( "An error occurred when deleting email: %1." ).arg( job->errorString() ) << endl; + _valid = false; + } + + _jobs->remove( job ); + + _kio->emitDeleteMailsProgress( _total - _jobs->count() ); + + if( _jobs->isEmpty() ) + { + _kio->emitDeleteMailsReady( _valid ); + disConnect(); + } +} + + +#include "kio_delete.moc" diff --git a/korn/tdeio_delete.h b/korn/tdeio_delete.h new file mode 100644 index 00000000..c084a58d --- /dev/null +++ b/korn/tdeio_delete.h @@ -0,0 +1,70 @@ +/* + * 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 + */ + +#ifndef MK_KIO_DELETE_H +#define MK_KIO_DELETE_H + +/* + * This class handles removing of selected messages. + * This class starts working when deleteMails() is called. + */ + +#include +class KKioDrop; +class KIO_Protocol; +class KornMailId; + +class KURL; +namespace TDEIO { class MetaData; class Job; class Slave; } + +template class TQPtrList; + +class KIO_Delete : public TQObject +{ Q_OBJECT + +public: + //constructors + KIO_Delete( TQObject * parent = 0, const char * name = 0 ); + ~KIO_Delete( ); + + //This function should be called if there are messages to be deleted. + bool deleteMails( TQPtrList< const KornMailId > *, KKioDrop* ); + + //This function should return false then and only then if an error occurred. + bool valid( ) { return _valid; } + +public slots: + //If this slot is called, the whole deletion is canceled. + void canceled( ); +private slots: + void slotResult( TDEIO::Job* ); + +private: + void disConnect( ); + bool setupSlave( KURL kurl, TDEIO::MetaData metadata, const KIO_Protocol *& protocol ); + void deleteItem( const KornMailId *item, KURL, TDEIO::MetaData, const KIO_Protocol *&); + void commitDelete( KURL, TDEIO::MetaData, const KIO_Protocol *& ); + + KKioDrop *_kio; + unsigned int _total; + TQPtrList< TDEIO::Job > *_jobs; + TDEIO::Slave *_slave; + bool _valid; +}; + +#endif //MK_KIO_DELETE_H diff --git a/korn/tdeio_proto.cpp b/korn/tdeio_proto.cpp new file mode 100644 index 00000000..e63a7166 --- /dev/null +++ b/korn/tdeio_proto.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2005, 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_proto.h" + +#include +#include + +#include + +TQMap< TQString, TQString >* KIO_Protocol::createConfig( TDEConfigGroup * group, const TQString& password ) const +{ + TQMap< TQString, TQString > *result = new TQMap< TQString, TQString >; + + result->insert( "name", group->readEntry( "name", "" ) ); + result->insert( "server", group->readEntry( "server", "" ) ); + result->insert( "port", group->readEntry( "port", "" ) ); + result->insert( "username", group->readEntry( "username", "" ) ); + result->insert( "password", password ); + result->insert( "mailbox", group->readEntry( "mailbox", "" ) ); + result->insert( "savepassword", group->readEntry( "savepassword", "false" ) ); + result->insert( "ssl", group->readEntry( "ssl", "false" ) ); + result->insert( "metadata", group->readEntry( "metadata", "" ) ); + + return result; +} + +void KIO_Protocol::clearFields( TQMap *map, const KIO_Protocol::Fields fields ) const +{ + if( fields & server ) + map->insert( "server", "" ); + if( fields & port ) + map->insert( "port", "" ); + if( fields & username ) + map->insert( "username", "" ); + if( fields & password ) + map->insert( "password", "" ); + if( fields & mailbox ) + map->insert( "mailbox", "" ); + if( fields & save_password ) + map->insert( "savepassword", "" ); + if( fields & metadata ) + map->insert( "metadata", "" ); +} + +void KIO_Protocol::readEntries( TQMap< TQString, TQString >* map ) const +{ + TQMap< TQString, TQString> *metadata = new TQMap< TQString, TQString >; + + if( map->contains( "metadata" ) ) + { + TQStringList list = TQStringList::split( ",", *map->find( "metadata" ) ); + TQStringList::Iterator it; + for( it = list.begin(); it != list.end(); ++it ) + { + int split = (*it).find( '=' ); + + metadata->insert( (*it).left( split ), (*it).right( (*it).length() - split - 1 ) ); + } + } + + this->readEntries( map, metadata ); + + delete metadata; +} diff --git a/korn/tdeio_proto.h b/korn/tdeio_proto.h new file mode 100644 index 00000000..510e97d3 --- /dev/null +++ b/korn/tdeio_proto.h @@ -0,0 +1,157 @@ +/* + * 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 + */ + +#ifndef MK_KIO_PROTO_H +#define MK_KIO_PROTO_H + +/* + * KIO can handle multiple protocols. But some protocols have their own + * manipulations of KURL or MetaData , and some protocols could do more then other + * protocols. So, this class is the generic class of a class specified + * by a protocol. + */ + +class TQString; +#include +#include +#include +#include "protocol.h" + +#include "kio.h" + +class KIO_Protocol : public Protocol +{ +public: + /* + * Constuctor; empty + */ + KIO_Protocol() {} + + /* + * Destructor; empty too + */ + virtual ~KIO_Protocol() {} + + /* + * Public enumeration + */ + enum DeleteTypeEnum { get, del }; + /** + * This are the implementation of the Protocol-functions + */ + virtual const Protocol* getProtocol( TDEConfigGroup* ) const { return this; } + + virtual KMailDrop* createMaildrop( TDEConfigGroup* config ) const { return new KKioDrop( config ); } + + virtual TQMap< TQString, TQString >* createConfig( TDEConfigGroup *group, const TQString& password ) const; + + /* + * @return: the name of the kio_slave + */ + virtual TQString protocol( bool ) const { return "file"; } + + /* + * @return: the name of the protocol used by the configuration + */ + virtual TQString configName() const { return "not specified"; } + + virtual bool connectionBased() const { return false; } + + /* + * The next four functions return the [capebilities] of a protocol. + * fullMessage means that by downloaden, the whole message is downloaded. + * if it is false, only the headers should be downloaded. + */ + virtual bool canReadSubjects() const { return false; } + virtual bool canDeleteMail() const { return false; } + virtual bool canReadMail() const { return false; } + virtual bool fullMessage() const { return false; } + + /* + * The following lines are the options in the configuration; + * true means that an option is enabled; + * false means that the option is disabled. + */ + //virtual int fields() const { return server | port | username | password | mailbox; } + //virtual int urlFields() const { return no_fields; } + virtual unsigned short defaultPort( bool ) const { return 0; } + + /* + * This sets the string of such fields in Configuration + */ + virtual TQString serverName() const { return i18n( "Server:" ); } + virtual TQString portName() const { return i18n( "Port:" ); } + virtual TQString usernameName() const { return i18n( "Username:" ); } + virtual TQString mailboxName() const { return i18n( "Mailbox:" ); } + virtual TQString passwordName() const { return i18n( "Password:" ); } + virtual TQString savePasswordName() const { return i18n( "Save password" ); } + virtual TQString authName() const { return i18n( "Authentication:" ); } + + /* + * The next function returns the method of deleting: some protoocols + * like to delete files with TDEIO::get; other with TDEIO::del + */ + virtual DeleteTypeEnum deleteFunction() const { return del; } + + /* + * The next options are the input for the Authentication Combo, seperated by '|'. + * The name should be the same as the auth-metadata. + */ + virtual TQStringList authList() const { return TQStringList::split( '|', "Plain", false ); } + + /* + * The next functions are manipulations of an KURL. + * At some points in the code, a KURL is used. But sometimes, + * these have to had a little retouch. That is possible with these function. + * + * For example, by imap, by default, the whole message is downloaded and marked as reed. + * By changing an option to the KURL path, this can be prevented. + * + * The most functions are recognized by name. + * commitDelete return true if a protocol has to confirm a deletion. + * It will be called after marking the messages for deletion. + * deleteCommitKURL is the KURL manipulator; the KURL is as in the settings. + * That KURL isn't retouch by deleteMailKURL. + */ + virtual void recheckConnectKURL( KURL &, TDEIO::MetaData & ) const { } + virtual void recheckKURL ( KURL &, TDEIO::MetaData & ) const { }; + virtual void readSubjectConnectKURL ( KURL & kurl, TDEIO::MetaData & ) const { kurl.setPath( "" ); } + virtual void readSubjectKURL ( KURL &, TDEIO::MetaData & ) const { } //For editing a kurl (adding extra options) + virtual void deleteMailConnectKURL( KURL & kurl, TDEIO::MetaData & ) const { kurl.setPath( "" ); } + virtual void deleteMailKURL ( KURL &, TDEIO::MetaData & ) const { } + virtual bool commitDelete() const { return false; } + virtual void deleteCommitKURL( KURL &, TDEIO::MetaData & ) const { } + virtual void readMailKURL ( KURL &, TDEIO::MetaData & ) const { } + + + virtual const KIO_Protocol* getKIOProtocol() const { return this; } + + virtual void readEntries( TQMap< TQString, TQString >* ) const; + virtual void readEntries( TQMap< TQString, TQString >*, TQMap< TQString, TQString >* ) const = 0; + +protected: + /* + * This enumeration is used when returning the capebilitys of a protocol + */ + enum Fields { no_fields = 0, server = 1, port = 2, username = 4, password = 8, + mailbox = 16, save_password = 32, metadata = 64 }; + + void clearFields( TQMap< TQString, TQString > *map, const Fields fields ) const; +}; + +#endif //MK_KIO_PROTO_H diff --git a/korn/tdeio_read.cpp b/korn/tdeio_read.cpp new file mode 100644 index 00000000..f98669d8 --- /dev/null +++ b/korn/tdeio_read.cpp @@ -0,0 +1,97 @@ +/* + * 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_read.h" + +#include "kio.h" +#include "kio_proto.h" +#include "mailid.h" +#include "stringid.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +KIO_Read::KIO_Read( TQObject * parent, const char * name ) + : TQObject( parent, name ), + _job( 0 ), + _message( 0 ) +{ + _message = new TQString; +} + +KIO_Read::~KIO_Read() +{ + delete _message; + delete _job; +} + +void KIO_Read::readMail( const KornMailId *& mailid, KKioDrop* drop ) +{ + _kio = drop; + KURL kurl = *_kio->_kurl; + TDEIO::MetaData metadata = *_kio->_metadata; + + kurl = dynamic_cast(mailid)->getId( ); + + _kio->_protocol->readMailKURL( kurl, metadata ); + + _job = TDEIO::get( kurl, false, false ); + _job->addMetaData( metadata ); + + connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); + connect( _job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ), this, TQT_SLOT( slotData( TDEIO::Job*, const TQByteArray & ) ) ); +} + +void KIO_Read::canceled( ) +{ + if( _job ) + delete _job; + _job = 0; +} + +void KIO_Read::slotResult( TDEIO::Job* job ) +{ + if( job != _job ) + kdWarning() << i18n( "Unknown job returned; I will try if this one will do... " ) << endl; + + if( job->error() ) + kdWarning() << i18n( "An error occurred when fetching the requested email: %1." ).arg( job->errorString() ) << endl; + + _kio->emitReadMailReady( _message ); + + *_message = ""; + _job = 0; +} + +void KIO_Read::slotData( TDEIO::Job* job, const TQByteArray & data ) +{ + if( job != _job ) + kdWarning() << i18n( "Unknown job returned; I will try if this one will do... " ) << endl; + + if( !data.isEmpty() ) + _message->append( data ); +} + +#include "kio_read.moc" diff --git a/korn/tdeio_read.h b/korn/tdeio_read.h new file mode 100644 index 00000000..3b1ddec8 --- /dev/null +++ b/korn/tdeio_read.h @@ -0,0 +1,61 @@ +/* + * 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 + */ + +#ifndef MK_KIO_READ_H +#define MK_KIO_READ_H + +//This class should be used if someone wants to read the Full Message + +#include + +class KKioDrop; +class KornMailId; + +class KURL; +namespace TDEIO { class MetaData; class Job; } +class KIO_Protocol; + +class TQString; + +class KIO_Read : public TQObject +{ Q_OBJECT + +public: + KIO_Read( TQObject * parent = 0, const char * name = 0 ); + ~KIO_Read(); + +public slots: + //This is the function which makes the nessesairy slaves for reading a message + void readMail( const KornMailId *&, KKioDrop* ); + //This function should be called if the user presses canceled. + void canceled(); +private: + KKioDrop *_kio; + TDEIO::Job *_job; + TQString *_message; + +signals: + //This signal is emitted when the whole message is read; the message got passed as TQString* + void ready( TQString* ); + +private slots: + void slotResult( TDEIO::Job* ); + void slotData( TDEIO::Job*, const TQByteArray& ); +}; + +#endif //MK_KIO_READ_H diff --git a/korn/tdeio_single_subject.cpp b/korn/tdeio_single_subject.cpp new file mode 100644 index 00000000..0c20b1ab --- /dev/null +++ b/korn/tdeio_single_subject.cpp @@ -0,0 +1,155 @@ +/* + * 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_single_subject.h" + +#include "mailsubject.h" +#include "kio_proto.h" +#include "stringid.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +KIO_Single_Subject::KIO_Single_Subject( TQObject * parent, const char * name, + KURL &kurl, TDEIO::MetaData &metadata, const KIO_Protocol * protocol, TDEIO::Slave *& slave, + const TQString &url, const long size ) + : TQObject( parent, name ) +{ + _kurl = new KURL( kurl ); + _metadata = new TDEIO::MetaData( metadata ); + _protocol = protocol; + _name = new TQString( url ); + _size = size; + _message = new TQString; + + init( slave ); +} + +KIO_Single_Subject::~KIO_Single_Subject( ) +{ + if( _job ) + TDEIO::Scheduler::cancelJob( _job ); + delete _kurl; + delete _metadata; + delete _name; + delete _message; +} + +void KIO_Single_Subject::init( TDEIO::Slave *& slave) +{ + _job = TDEIO::get( *_kurl, false, false ); + _job->addMetaData( *_metadata ); + + connect( _job, TQT_SIGNAL( result( TDEIO::Job* ) ), this, TQT_SLOT( slotResult( TDEIO::Job* ) ) ); + connect( _job, TQT_SIGNAL( data (TDEIO::Job *, const TQByteArray &) ), + this, TQT_SLOT( slotData(TDEIO::Job *, const TQByteArray &) ) ); + + if( _protocol->connectionBased( ) && slave ) + TDEIO::Scheduler::assignJobToSlave( slave , _job ); + else + TDEIO::Scheduler::scheduleJob( _job ); + +} + +void KIO_Single_Subject::parseMail( TQString * message, KornMailSubject *subject, bool fullMessage ) +{ + TQTextStream stream( message, IO_ReadOnly ); + TQString line; + TQRegExp rx_sender( "^[fF]rom: " ); //Ex: From: ... + TQRegExp rx_sender_has_name1( "^[fF]rom:\\s*(\\w+[\\w\\s]*)\\<" ); //Ex: From: A name + TQRegExp rx_sender_has_name2( "^[fF]rom:\\s*\\\"\\s*(\\w+[\\w\\s]*)\\\""); //Ex: From: "A name" + TQRegExp rx_subject( "^[sS]ubject: " ); //Ex: Subject: ... + TQRegExp rx_date ( "^[dD]ate: "); + bool inheader = true; + int fieldnumber = 0; + + while ( ! stream.atEnd() ) + { + line = stream.readLine(); + if( line.isEmpty() && fieldnumber >= 2 ) + inheader = false; + + if( inheader ) + { + if( rx_sender.search( line ) == 0 ) + { + if( rx_sender_has_name1.search( line ) == 0 ) + subject->setSender( rx_sender_has_name1.cap( 1 ) ); + else if(rx_sender_has_name2.search( line ) == 0) + subject->setSender( rx_sender_has_name2.cap( 1 ) ); + else + subject->setSender( line.remove( rx_sender ) ); + ++fieldnumber; + } + else if( rx_subject.search( line ) == 0 ) + { + subject->setSubject( line.remove( rx_subject ) ); + ++fieldnumber; + } + else if( rx_date.search( line ) == 0 ) + { + subject->setDate( KRFCDate::parseDate( line.right( line.length() - 6 ) ) ); + ++fieldnumber; + } + } + } + + subject->setHeader( *message, fullMessage ); +} + +void KIO_Single_Subject::slotData( TDEIO::Job* job, const TQByteArray& data ) +{ + if( job != _job ) + kdWarning() << i18n( "Got invalid job; something strange happened?" ) << endl; + if( !data.isEmpty() ) + _message->append( data ); +} + +//TDEIO::Scheduler::disconnectSlave missing if connection stops +void KIO_Single_Subject::slotResult( TDEIO::Job *job ) +{ + if( job != _job ) + kdWarning() << i18n( "Got invalid job; something strange happened?" ) << endl; + + if( job->error() ) + { + kdWarning() << i18n( "Error when fetching %1: %2" ).arg( *_name ).arg( job->errorString() ) << endl; + } else { + KornMailSubject * mailSubject = new KornMailSubject( new KornStringId( *_name ), 0 ); + parseMail( _message, mailSubject, _protocol->fullMessage() ); + mailSubject->decodeHeaders(); + mailSubject->setSize( _size ); + emit readSubject( mailSubject ); + } + + _job = 0; + + emit finished( this ); +} + +#include "kio_single_subject.moc" diff --git a/korn/tdeio_single_subject.h b/korn/tdeio_single_subject.h new file mode 100644 index 00000000..9aac8baa --- /dev/null +++ b/korn/tdeio_single_subject.h @@ -0,0 +1,68 @@ +/* + * 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 + */ + +#ifndef MK_KIO_SINGEL_SUBJECT_H +#define MK_KIO_SINGEL_SUBJECT_H + +//This function reads a single subject + +#include +#include + +class KornMailSubject; + +class KURL; +namespace TDEIO { class MetaData; class Job; class TransferJob; class Slave; } +class KIO_Protocol; + +class TQString; + +class KIO_Single_Subject : public TQObject +{ Q_OBJECT + +public: + KIO_Single_Subject( TQObject * parent, const char * name, KURL &, TDEIO::MetaData &, const KIO_Protocol *, + TDEIO::Slave *&, const TQString &, const long ); + ~KIO_Single_Subject( ); + + //This functions try's te parse EMail; data, sender names and so on... + static void parseMail( TQString * message, KornMailSubject *subject, bool ); + +private: + TQString *_message; + TQString *_name; + KURL *_kurl; + const KIO_Protocol *_protocol; + TDEIO::MetaData *_metadata; + TDEIO::TransferJob* _job; + long _size; + + void init( TDEIO::Slave*& ); + +private slots: + void slotResult( TDEIO::Job* ); + void slotData( TDEIO::Job*, const TQByteArray& ); + +signals: + //This signal is emitted if the headers are read and put into a KornMailSubject* + void readSubject( KornMailSubject* ); + //This signal is emitted if this class could be destroyed. + void finished( KIO_Single_Subject* ); +}; + +#endif diff --git a/korn/tdeio_subjects.cpp b/korn/tdeio_subjects.cpp new file mode 100644 index 00000000..f40a86f6 --- /dev/null +++ b/korn/tdeio_subjects.cpp @@ -0,0 +1,176 @@ +/* + * 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_subjects.h" + +#include "kio.h" +#include "kio_single_subject.h" +#include "kio_proto.h" +#include "mailsubject.h" + +#include +#include +#include + +#include +#include +#include + +KIO_Subjects::KIO_Subjects( TQObject * parent, const char * name ) + : TQObject( parent, name ), + _protocol( 0 ), + _slave( 0 ), + _valid( true ) +{ + _jobs = new TQPtrList; + _kurl = new KURL; + _metadata = new TDEIO::MetaData; + + _jobs->setAutoDelete( true ); +} + +KIO_Subjects::~KIO_Subjects( ) +{ + delete _jobs; + delete _kurl; + delete _metadata; + _protocol = 0; +} + +void KIO_Subjects::doReadSubjects( KKioDrop *drop ) +{ + TQValueList::ConstIterator it; + TQValueList::ConstIterator end_it = drop->_mailurls->end(); + + _kio = drop; + _protocol = _kio->_protocol; + *_kurl = *_kio->_kurl; + *_metadata = *_kio->_metadata; + + if( _jobs->count() > 0 ) + kdWarning() << i18n( "Already a slave pending." ) << endl; + + _jobs->clear( ); + + //Open connection + getConnection( ); + + //Open jobs for easy item in the list + for( it = _kio->_mailurls->begin(); it != end_it; it++ ) + startJob( (*it).name, (*it).size ); + + //close connection for trivial situations (empty list) + disConnect( true ); + + //passing number of subjects for progress bar. + _kio->emitReadSubjectsTotalSteps( _jobs->count() ); +} + +void KIO_Subjects::getConnection( ) +{ + KURL kurl = *_kurl; + TDEIO::MetaData metadata = *_metadata; + + if( _slave ) + { + TDEIO::Scheduler::disconnectSlave( _slave ); + _slave = 0; + } + + if( _protocol->connectionBased( ) ) + { + _protocol->readSubjectConnectKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); + + if( ! ( _slave = TDEIO::Scheduler::getConnectedSlave( kurl, metadata ) ) ) + { + kdWarning() << i18n( "Not able to open a kio-slave for %1." ).arg( _protocol->configName() ); + _kio->emitShowPassivePopup( i18n( "Not able to open a kio-slave for %1." ).arg( _protocol->configName() ) ); + _valid = false; + _kio->emitValidChanged(); + _slave = 0; + _kio->emitReadSubjectsReady( false ); + return; + } + } +} + +void KIO_Subjects::startJob( const TQString &name, const long size ) +{ + KURL kurl = *_kurl; + TDEIO::MetaData metadata = *_metadata; + KIO_Single_Subject *subject; + + kurl = name; + + _protocol->readSubjectKURL( kurl, metadata ); + + if( kurl.port() == 0 ) + kurl.setPort( _protocol->defaultPort( _kio->_ssl ) ); + + subject = new KIO_Single_Subject( this, name.latin1(), kurl, metadata, _protocol, _slave, name, size ); + + connect( subject, TQT_SIGNAL( readSubject( KornMailSubject* ) ), this, TQT_SLOT( slotReadSubject( KornMailSubject* ) ) ); + connect( subject, TQT_SIGNAL( finished( KIO_Single_Subject* ) ), this, TQT_SLOT( slotFinished( KIO_Single_Subject* ) ) ); + + _jobs->append( subject ); +} + +void KIO_Subjects::disConnect( bool result ) +{ + if( _jobs->isEmpty() ) + { + if( _slave ) + { + TDEIO::Scheduler::disconnectSlave( _slave ); + _slave = 0; + } + _kio->emitReadSubjectsReady( result ); + } +} + +void KIO_Subjects::cancelled( ) +{ + _jobs->clear(); + //_slave died in cancelJob with is by called from the destructor of KIO_Single_Subject, + //withs is by called by _jobs->clear because autoRemove equals true. + _slave = 0; + disConnect( false ); +} + +void KIO_Subjects::slotReadSubject( KornMailSubject* subject ) +{ + _valid = true; + _kio->emitValidChanged(); + subject->setMailDrop( _kio ); + _kio->emitReadSubjectsRead( subject ); +} + +void KIO_Subjects::slotFinished( KIO_Single_Subject* item ) +{ + //Remove sender.... I didn't know of the computer gonna like me, but it seems he does :) + _jobs->remove( item ); + + _kio->emitReadSubjectsProgress( _jobs->count( ) ); + + disConnect( true ); //Only works when all jobs are finished. +} + +#include "kio_subjects.moc" diff --git a/korn/tdeio_subjects.h b/korn/tdeio_subjects.h new file mode 100644 index 00000000..018369de --- /dev/null +++ b/korn/tdeio_subjects.h @@ -0,0 +1,75 @@ +/* + * 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 + */ + +#ifndef MK_KIO_SUBJECTS_H +#define MK_KIO_SUBJECTS_H + +//This class calls other class to read all the subjects + +#include +class KKioDrop; +class KIO_Single_Subject; +class KIO_Protocol; +class KornMailSubject; + +namespace TDEIO { class MetaData; class Slave; } +class KURL; + +template class TQPtrList; +class TQString; +template class TQValueList; + +class KIO_Subjects : public TQObject +{ Q_OBJECT + +public: + KIO_Subjects( TQObject * parent, const char * name ); + ~KIO_Subjects( ); + + //This function let it start fetching headers. + void doReadSubjects( KKioDrop* ); + + //This function should return true then and only then of no error occurred. + bool valid( ) { return _valid; } + +private: + KKioDrop *_kio; + KURL *_kurl; + TDEIO::MetaData *_metadata; + const KIO_Protocol *_protocol; + TQPtrList *_jobs; + TDEIO::Slave *_slave; + bool _valid; + + //Opens a connection. + void getConnection( ); + //Start a job; the job itself is executed in KIO_Single_Subject + void startJob( const TQString&, const long ); + //Disconnect the connection + void disConnect( bool ); + +public slots: + //This function called the fetching of headers. + void cancelled( ); + +private slots: + void slotReadSubject( KornMailSubject* ); + void slotFinished( KIO_Single_Subject* ); +}; + +#endif -- cgit v1.2.3