• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

knode

  • sources
  • kde-4.12
  • kdepim
  • knode
knjobdata.cpp
Go to the documentation of this file.
1 /*
2  KNode, the KDE newsreader
3  Copyright (c) 1999-2005 the KNode authors.
4  See file AUTHORS for details
5 
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
13 */
14 
15 
16 #include <kdebug.h>
17 #include <klocale.h>
18 #include <kio/job.h>
19 
20 #include <libkdepim/progresswidget/progressmanager.h>
21 
22 #include "knarticle.h"
23 #include "knglobals.h"
24 #include "knnntpaccount.h"
25 #include "scheduler.h"
26 
27 
28 #include <QTimer>
29 
30 KNJobConsumer::KNJobConsumer()
31 {
32 }
33 
34 
35 KNJobConsumer::~KNJobConsumer()
36 {
37  for ( QList<KNJobData*>::Iterator it = mJobs.begin(); it != mJobs.end(); ++it )
38  (*it)->c_onsumer = 0;
39 }
40 
41 
42 void KNJobConsumer::emitJob( KNJobData *j )
43 {
44  if ( j ) {
45  mJobs.append( j );
46  knGlobals.scheduler()->addJob( j );
47  }
48 }
49 
50 
51 void KNJobConsumer::jobDone( KNJobData *j )
52 {
53  if ( j && mJobs.removeAll( j ) )
54  processJob( j );
55 }
56 
57 void KNJobConsumer::cancelJobs( KNJobItem::Ptr item )
58 {
59  Q_FOREACH( KNJobData *job, mJobs ) {
60  if ( job->data() == item ) {
61  job->d_ata.reset();
62  job->cancel();
63  }
64  }
65 }
66 
67 
68 void KNJobConsumer::processJob( KNJobData *j )
69 {
70  delete j;
71 }
72 
73 
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 )
82 {
83  d_ata->setLocked(true);
84 }
85 
86 
87 
88 KNJobData::~KNJobData()
89 {
90  if ( d_ata ) {
91  d_ata->setLocked( false );
92  }
93 }
94 
95 
96 void KNJobData::notifyConsumer()
97 {
98 
99  if(c_onsumer)
100  c_onsumer->jobDone(this);
101  else
102  delete this;
103 }
104 
105 void KNJobData::cancel()
106 {
107  mCanceled = true;
108  if ( mJob ) {
109  mJob->kill();
110  }
111  if ( mProgressItem ) {
112  mProgressItem->setStatus( "Canceled" );
113  mProgressItem->setComplete();
114  mProgressItem = 0;
115  }
116  emitFinished();
117 }
118 
119 void KNJobData::emitFinished()
120 {
121  QTimer::singleShot( 0, this, SLOT(slotEmitFinished()) );
122 }
123 
124 void KNJobData::setupKJob(KJob * job)
125 {
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)) );
132  }
133 }
134 
135 void KNJobData::setupKIOJob( KIO::Job *job )
136 {
137  if ( job ) {
138  if ( account() ) {
139  if ( account()->encryption() == KNServerInfo::TLS )
140  job->addMetaData( "tls", "on" );
141  else
142  job->addMetaData( "tls", "off" );
143  }
144  job->setUiDelegate(0);
145  setupKJob( job );
146  }
147 }
148 
149 void KNJobData::createProgressItem()
150 {
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();
160  }
161  bool encr = false;
162  if ( acc && acc->encryption() != KNServerInfo::None )
163  encr = true;
164  mProgressItem = KPIM::ProgressManager::createProgressItem( 0,
165  KPIM::ProgressManager::getUniqueID(), msg, i18n( "Waiting..." ), true, encr );
166 }
167 
168 void KNJobData::slotJobPercent( KJob*, unsigned long percent )
169 {
170  kDebug(5003) <<"Progress:" << percent;
171  setProgress( percent );
172 }
173 
174 void KNJobData::slotJobInfoMessage( KJob*, const QString &msg )
175 {
176  kDebug(5003) <<"Status:" << msg;
177  setStatus( msg );
178 }
179 
180 void KNJobData::slotEmitFinished( )
181 {
182  emit finished( this );
183 }
184 
185 KUrl KNJobData::baseUrl() const
186 {
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() );
197  }
198  return url;
199 }
200 
201 void KNJobData::setError( int err, const QString & errMsg )
202 {
203  mError = err;
204  mErrorString = errMsg;
205 }
206 
207 #include "knjobdata.moc"
KNNntpAccount
Represents an account on a news server.
Definition: knnntpaccount.h:56
KNServerInfo::SSL
Definition: knserverinfo.h:32
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(const QString &label)
KNJobData::setStatus
void setStatus(const QString &msg)
Set the status message of the progress item if available.
Definition: knjobdata.h:164
KNJobConsumer::emitJob
void emitJob(KNJobData *j)
Send the job to the scheduler and append it to the job queue.
Definition: knjobdata.cpp:42
KNJobData::finished
void finished(KNJobData *)
Emitted when a job has been finished.
KNJobData
Abstract base class for all KNode internal jobs.
Definition: knjobdata.h:101
KNJobData::mProgressItem
KPIM::ProgressItem * mProgressItem
The progress item representing this job to the user.
Definition: knjobdata.h:214
KNJobData::cancel
void cancel()
Cancels this job.
Definition: knjobdata.cpp:105
KNJobConsumer::KNJobConsumer
KNJobConsumer()
Definition: knjobdata.cpp:30
KNNntpAccount::Ptr
boost::shared_ptr< KNNntpAccount > Ptr
Shared pointer to a KNNntpAccount.
Definition: knnntpaccount.h:62
KNJobData::mJob
QPointer< KJob > mJob
An associated KJob.
Definition: knjobdata.h:212
KNJobData::mError
int mError
The job error code (see KIO::Error).
Definition: knjobdata.h:205
knnntpaccount.h
KNServerInfo::TLS
Definition: knserverinfo.h:32
KPIM::ProgressManager::getUniqueID
static QString getUniqueID()
KNJobData::KNJobData
KNJobData(jobType t, KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i)
Definition: knjobdata.cpp:75
scheduler.h
KNJobData::c_onsumer
KNJobConsumer * c_onsumer
Definition: knjobdata.h:210
KNJobData::mErrorString
QString mErrorString
The error message.
Definition: knjobdata.h:207
KNJobConsumer::mJobs
QList< KNJobData * > mJobs
List of all active jobs.
Definition: knjobdata.h:68
KPIM::ProgressItem::setComplete
void setComplete()
KNJobData::type
jobType type() const
Definition: knjobdata.h:120
progressmanager.h
KNJobData::data
KNJobItem::Ptr data() const
Definition: knjobdata.h:123
KNJobData::account
KNServerInfo::Ptr account() const
Definition: knjobdata.h:122
KNJobData::~KNJobData
~KNJobData()
Definition: knjobdata.cpp:88
KNJobData::notifyConsumer
void notifyConsumer()
Definition: knjobdata.cpp:96
KNServerInfo::None
Definition: knserverinfo.h:32
KNJobData::jobType
jobType
Definition: knjobdata.h:109
KNJobData::setupKJob
void setupKJob(KJob *job)
Connects progress signals.
Definition: knjobdata.cpp:124
KNJobConsumer
Base class for classes that want to create and schedule jobs.
Definition: knjobdata.h:39
KNJobItem::Ptr
boost::shared_ptr< KNJobItem > Ptr
Shared pointer to a KNJobItem.
Definition: knjobdata.h:80
KNJobConsumer::cancelJobs
void cancelJobs(boost::shared_ptr< KNJobItem > item)
Find any job related to a job item and cancel it.
Definition: knjobdata.cpp:57
knglobals.h
KNJobData::baseUrl
KUrl baseUrl() const
Returns a correctly set up KUrl according to the encryption and authentication settings for KIO slave...
Definition: knjobdata.cpp:185
KNJobConsumer::~KNJobConsumer
virtual ~KNJobConsumer()
Definition: knjobdata.cpp:35
KNJobData::createProgressItem
void createProgressItem()
Creates a KPIM::ProgressItem for this job.
Definition: knjobdata.cpp:149
KNJobData::d_ata
KNJobItem::Ptr d_ata
Definition: knjobdata.h:202
KNJobData::setProgress
void setProgress(unsigned int progress)
Set the progress value of the progress item if available.
Definition: knjobdata.h:168
KNJobData::emitFinished
void emitFinished()
Emits the finished() signal via a single-shot timer.
Definition: knjobdata.cpp:119
knarticle.h
KNJobData::mCanceled
bool mCanceled
Cancel status flag.
Definition: knjobdata.h:209
KNServerInfo::Ptr
boost::shared_ptr< KNServerInfo > Ptr
Shared pointer to a KNServerInfo.
Definition: knserverinfo.h:37
KNJobData::JTmail
Definition: knjobdata.h:114
KNJobData::setError
void setError(int err, const QString &errMsg)
Set job error information.
Definition: knjobdata.cpp:201
KNJobConsumer::processJob
virtual void processJob(KNJobData *j)
The actual work is done here.
Definition: knjobdata.cpp:68
knGlobals
#define knGlobals
Keep compatibility with the old way.
Definition: knglobals.h:28
KJob
KNJobData::setupKIOJob
void setupKIOJob(KIO::Job *job)
Sets TLS metadata and connects the given KIO job to the progress item.
Definition: knjobdata.cpp:135
KPIM::ProgressItem::setStatus
void setStatus(const QString &v)
QList
KNJobConsumer::jobDone
void jobDone(KNJobData *j)
Remove the job from the joblist and process it by calling processJob.
Definition: knjobdata.cpp:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knode

Skip menu "knode"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal