2 KNode, the KDE newsreader
3 Copyright (c) 1999-2005 the KNode authors.
4 See file AUTHORS for details
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software Foundation,
12 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
20 #include <libkdepim/progresswidget/progressmanager.h>
22 #include "knarticle.h"
23 #include "knglobals.h"
24 #include "knnntpaccount.h"
25 #include "scheduler.h"
30 KNJobConsumer::KNJobConsumer()
35 KNJobConsumer::~KNJobConsumer()
37 for ( QList
<KNJobData
*>::Iterator it
= mJobs
.begin(); it
!= mJobs
.end(); ++it
)
42 void KNJobConsumer::emitJob( KNJobData
*j
)
46 knGlobals
.scheduler()->addJob( j
);
51 void KNJobConsumer::jobDone( KNJobData
*j
)
53 if ( j
&& mJobs
.removeAll( j
) )
57 void KNJobConsumer::cancelJobs( KNJobItem::Ptr item
)
59 Q_FOREACH( KNJobData
*job
, mJobs
) {
60 if ( job
->data() == item
) {
68 void KNJobConsumer::processJob( KNJobData
*j
)
74 // the assingment of a_ccount may cause race conditions, check again.... (CG)
75 KNJobData::KNJobData( jobType t
, KNJobConsumer
*c
, KNServerInfo::Ptr a
, KNJobItem::Ptr i
) :
76 t_ype(t
), d_ata(i
), a_ccount(a
),
83 d_ata
->setLocked(true);
88 KNJobData::~KNJobData()
91 d_ata
->setLocked( false );
96 void KNJobData::notifyConsumer()
100 c_onsumer
->jobDone(this);
105 void KNJobData::cancel()
111 if ( mProgressItem
) {
112 mProgressItem
->setStatus( "Canceled" );
113 mProgressItem
->setComplete();
119 void KNJobData::emitFinished()
121 QTimer::singleShot( 0, this, SLOT(slotEmitFinished()) );
124 void KNJobData::setupKJob(KJob
* job
)
128 connect( job
, SIGNAL(percent(KJob
*,ulong
)),
129 SLOT(slotJobPercent(KJob
*,ulong
)) );
130 connect( job
, SIGNAL(infoMessage(KJob
*,QString
)),
131 SLOT(slotJobInfoMessage(KJob
*,QString
)) );
135 void KNJobData::setupKIOJob( KIO::Job
*job
)
139 if ( account()->encryption() == KNServerInfo::TLS
)
140 job
->addMetaData( "tls", "on" );
142 job
->addMetaData( "tls", "off" );
144 job
->setUiDelegate(0);
149 void KNJobData::createProgressItem()
153 KNNntpAccount::Ptr acc
= boost::static_pointer_cast
<KNNntpAccount
>( account() );
154 QString msg
= i18n( "KNode" );
155 if ( type() == JTmail
)
156 msg
= i18n( "Sending message" );
161 KPIM::ProgressItem::CryptoStatus encr
= KPIM::ProgressItem::Unencrypted
;
162 if ( acc
&& acc
->encryption() != KNServerInfo::None
)
163 encr
= KPIM::ProgressItem::Encrypted
;
164 mProgressItem
= KPIM::ProgressManager::createProgressItem( 0,
165 KPIM::ProgressManager::getUniqueID(), msg
, i18n( "Waiting..." ), true, encr
);
168 void KNJobData::slotJobPercent( KJob
*, unsigned long percent
)
170 kDebug(5003) <<"Progress:" << percent
;
171 setProgress( percent
);
174 void KNJobData::slotJobInfoMessage( KJob
*, const QString
&msg
)
176 kDebug(5003) <<"Status:" << msg
;
180 void KNJobData::slotEmitFinished( )
182 emit
finished( this );
185 KUrl
KNJobData::baseUrl() const
188 if ( account()->encryption() == KNServerInfo::SSL
)
189 url
.setProtocol( "nntps" );
191 url
.setProtocol( "nntp" );
192 url
.setHost( account()->server() );
193 url
.setPort( account()->port() );
194 if ( account()->needsLogon() ) {
195 url
.setUserName( account()->user() );
196 url
.setPass( account()->pass() );
201 void KNJobData::setError( int err
, const QString
& errMsg
)
204 mErrorString
= errMsg
;