SVN_SILENT made messages (.desktop file)
[kdepim.git] / knode / knjobdata.cpp
blobc29c39a871f351658c9dd245b59eec85f29ed743
1 /*
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
16 #include <kdebug.h>
17 #include <klocale.h>
18 #include <kio/job.h>
20 #include <libkdepim/progresswidget/progressmanager.h>
22 #include "knarticle.h"
23 #include "knglobals.h"
24 #include "knnntpaccount.h"
25 #include "scheduler.h"
28 #include <QTimer>
30 KNJobConsumer::KNJobConsumer()
35 KNJobConsumer::~KNJobConsumer()
37 for ( QList<KNJobData*>::Iterator it = mJobs.begin(); it != mJobs.end(); ++it )
38 (*it)->c_onsumer = 0;
42 void KNJobConsumer::emitJob( KNJobData *j )
44 if ( j ) {
45 mJobs.append( j );
46 knGlobals.scheduler()->addJob( j );
51 void KNJobConsumer::jobDone( KNJobData *j )
53 if ( j && mJobs.removeAll( j ) )
54 processJob( j );
57 void KNJobConsumer::cancelJobs( KNJobItem::Ptr item )
59 Q_FOREACH( KNJobData *job, mJobs ) {
60 if ( job->data() == item ) {
61 job->d_ata.reset();
62 job->cancel();
68 void KNJobConsumer::processJob( KNJobData *j )
70 delete 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),
77 mError( 0 ),
78 mCanceled( false ),
79 c_onsumer( c ),
80 mJob( 0 ),
81 mProgressItem( 0 )
83 d_ata->setLocked(true);
88 KNJobData::~KNJobData()
90 if ( d_ata ) {
91 d_ata->setLocked( false );
96 void KNJobData::notifyConsumer()
99 if(c_onsumer)
100 c_onsumer->jobDone(this);
101 else
102 delete this;
105 void KNJobData::cancel()
107 mCanceled = true;
108 if ( mJob ) {
109 mJob->kill();
111 if ( mProgressItem ) {
112 mProgressItem->setStatus( "Canceled" );
113 mProgressItem->setComplete();
114 mProgressItem = 0;
116 emitFinished();
119 void KNJobData::emitFinished()
121 QTimer::singleShot( 0, this, SLOT(slotEmitFinished()) );
124 void KNJobData::setupKJob(KJob * job)
126 mJob = job;
127 if ( 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 )
137 if ( job ) {
138 if ( account() ) {
139 if ( account()->encryption() == KNServerInfo::TLS )
140 job->addMetaData( "tls", "on" );
141 else
142 job->addMetaData( "tls", "off" );
144 job->setUiDelegate(0);
145 setupKJob( job );
149 void KNJobData::createProgressItem()
151 if ( mProgressItem )
152 return;
153 KNNntpAccount::Ptr acc = boost::static_pointer_cast<KNNntpAccount>( account() );
154 QString msg = i18n( "KNode" );
155 if ( type() == JTmail )
156 msg = i18n( "Sending message" );
157 else {
158 if ( acc )
159 msg = acc->name();
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;
177 setStatus( msg );
180 void KNJobData::slotEmitFinished( )
182 emit finished( this );
185 KUrl KNJobData::baseUrl() const
187 KUrl url;
188 if ( account()->encryption() == KNServerInfo::SSL )
189 url.setProtocol( "nntps" );
190 else
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() );
198 return url;
201 void KNJobData::setError( int err, const QString & errMsg )
203 mError = err;
204 mErrorString = errMsg;