• 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
nntpjobs.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2005 by Volker Krause <vkrause@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  You should have received a copy of the GNU General Public License
9  along with this program; if not, write to the Free Software Foundation,
10  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
11 */
12 
13 #include "nntpjobs.h"
14 
15 #include "kngroup.h"
16 #include "kngroupmanager.h"
17 #include "knserverinfo.h"
18 #include <kdebug.h>
19 #include <klocale.h>
20 #include <QDir>
21 
22 KNode::GroupListJob::GroupListJob( KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool incremental )
23  : KNJobData( KNJobData::JTFetchGroups, c, a, i ),
24  mIncremental( incremental )
25 {
26 }
27 
28 void KNode::GroupListJob::execute()
29 {
30  mGroupList.clear();
31 
32  KNGroupListData::Ptr target = boost::static_pointer_cast<KNGroupListData>( data() );
33 
34  KUrl destination = baseUrl();
35  QStringList query;
36  if ( target->getDescriptions )
37  query << "desc=true";
38  if ( mIncremental )
39  query << QString( "since=%1%2%3+000000" )
40  .arg( target->fetchSince.year() % 100, 2, 10, QChar( '0' ) )
41  .arg( target->fetchSince.month(), 2, 10, QChar( '0' ) )
42  .arg( target->fetchSince.day(), 2, 10, QChar( '0' ) );
43  destination.setQuery( query.join( "&" ) );
44  KIO::ListJob* job = KIO::listDir( destination, KIO::HideProgressInfo, true );
45  connect( job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
46  SLOT(slotEntries(KIO::Job*,KIO::UDSEntryList)) );
47  connect( job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)) );
48  setupKIOJob( job );
49 }
50 
51 void KNode::GroupListJob::slotEntries( KIO::Job * job, const KIO::UDSEntryList & list )
52 {
53  Q_UNUSED( job );
54  KNGroupListData::Ptr target = boost::static_pointer_cast<KNGroupListData>( data() );
55 
56  QString name, desc;
57  bool subscribed;
58  KNGroup::Status access;
59  for( KIO::UDSEntryList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
60  access = KNGroup::unknown;
61  name = (*it).stringValue( KIO::UDSEntry::UDS_NAME );
62  desc = (*it).stringValue( KIO::UDSEntry::UDS_EXTRA );
63 
64  int value = (*it).numberValue( KIO::UDSEntry::UDS_ACCESS, -1 );
65  if ( value != -1 ) {
66  if( value & S_IWOTH )
67  access = KNGroup::postingAllowed;
68  else if ( value & S_IWGRP )
69  access = KNGroup::moderated;
70  else
71  access = KNGroup::readOnly;
72  }
73 
74  if ( name.isEmpty() )
75  continue;
76  if ( target->subscribed.contains( name ) ) {
77  target->subscribed.removeAll( name ); // group names are unique, we wont find it again anyway...
78  subscribed = true;
79  } else {
80  subscribed = false;
81  }
82  kDebug() << "Found group " << name;
83  if ( mIncremental )
84  mGroupList.append(KNGroupInfo( name, desc, true, subscribed, access ) );
85  else
86  target->groups->append(KNGroupInfo( name, desc, false, subscribed, access ) );
87  }
88 }
89 
90 void KNode::GroupListJob::slotResult( KJob * job )
91 {
92  if ( job->error() )
93  setError( job->error(), job->errorString() );
94  else {
95  KNGroupListData::Ptr target = boost::static_pointer_cast<KNGroupListData>( data() );
96 
97  // TODO: use thread weaver here?
98  if ( mIncremental ) {
99  setStatus( i18n("Loading group list from disk...") );
100  if ( !target->readIn( this ) ) {
101  setError( KIO::ERR_COULD_NOT_READ, i18n("Unable to read the group list file") );
102  emitFinished();
103  return;
104  }
105  target->merge( &mGroupList );
106  }
107  setStatus( i18n("Writing group list to disk...") );
108 
109  if ( !target->writeOut() )
110  setError( KIO::ERR_COULD_NOT_WRITE, i18n("Unable to write the group list file") );
111  }
112 
113  emitFinished();
114 }
115 
116 
117 
118 KNode::GroupLoadJob::GroupLoadJob( KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i ) :
119  KNJobData( KNJobData::JTLoadGroups, c, a, i )
120 {
121 }
122 
123 void KNode::GroupLoadJob::execute( )
124 {
125  KNGroupListData::Ptr target = boost::static_pointer_cast<KNGroupListData>( data() );
126 
127  setStatus( i18n("Loading group list from disk...") );
128  // TODO: use the thread weaver here
129  if ( !target->readIn( this ) )
130  setError( KIO::ERR_COULD_NOT_READ, i18n("Unable to read the group list file") );
131 
132  emitFinished();
133 }
134 
135 
136 
137 KNode::ArticleListJob::ArticleListJob( KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool silent ) :
138  KNJobData( JTfetchNewHeaders, c, a, i ),
139  mSilent( silent )
140 {
141 }
142 
143 void KNode::ArticleListJob::execute()
144 {
145  mArticleList.clear();
146 
147  KNGroup::Ptr target = boost::static_pointer_cast<KNGroup>( data() );
148 
149  KUrl destination = baseUrl();
150  destination.setPath( target->groupname() );
151  QStringList query;
152  query << "first=" + QString::number( target->lastNr() + 1 );
153  if ( target->lastNr() <= 0 ) // first fetch
154  query << "max=" + QString::number( target->maxFetch() );
155  destination.setQuery( query.join( "&" ) );
156  KIO::ListJob* job = KIO::listDir( destination, KIO::HideProgressInfo, true );
157  connect( job, SIGNAL(entries(KIO::Job*,KIO::UDSEntryList)),
158  SLOT(slotEntries(KIO::Job*,KIO::UDSEntryList)) );
159  connect( job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)) );
160  setupKIOJob( job );
161 }
162 
163 void KNode::ArticleListJob::slotEntries( KIO::Job * job, const KIO::UDSEntryList & list )
164 {
165  Q_UNUSED( job );
166  mArticleList += list;
167 }
168 
169 void KNode::ArticleListJob::slotResult( KJob * _job )
170 {
171  Q_ASSERT( mJob == _job );
172  KIO::Job *job = static_cast<KIO::Job*>( _job );
173  if ( job->error() )
174  setError( job->error(), job->errorString() );
175  else {
176  createProgressItem();
177 
178  KNGroup::Ptr target = boost::static_pointer_cast<KNGroup>( data() );
179  target->setLastFetchCount( 0 );
180 
181  setStatus( i18n("Sorting...") );
182 
183  if ( job->metaData().contains( "FirstSerialNumber" ) ) {
184  int firstSerNum = job->metaData()["FirstSerialNumber"].toInt();
185  target->setFirstNr( firstSerNum );
186  }
187 
188  target->insortNewHeaders( mArticleList, this );
189 
190  if ( job->metaData().contains( "LastSerialNumber" ) ) {
191  int lastSerNum = job->metaData()["LastSerialNumber"].toInt();
192  target->setLastNr( lastSerNum );
193  }
194  }
195 
196  setComplete();
197 
198  emitFinished();
199 }
200 
201 
202 
203 KNode::ArticleFetchJob::ArticleFetchJob( KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool parse ) :
204  KNJobData( JTfetchArticle, c, a, i ),
205  mParseArticle( parse )
206 {
207 }
208 
209 void KNode::ArticleFetchJob::execute()
210 {
211  KNRemoteArticle::Ptr target = boost::static_pointer_cast<KNRemoteArticle>( data() );
212 
213  KUrl url = baseUrl();
214 
215  url.addPath( boost::static_pointer_cast<KNGroup>( target->collection() )->groupname() );
216 
217  // By default, fetch articles by their server-side Id.
218  // (some server does not understand the "ARTICLE <msg-id>" command correctly (bug #193550))
219  if ( target->articleNumber() != -1 ) {
220  url.addPath( QString::number( target->articleNumber() ) );
221  } else {
222  // User asked to fetch a message by its msg-id
223  url.addPath( target->messageID()->as7BitString( false ) );
224  }
225 
226  KIO::Job* job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo );
227  connect( job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)) );
228  setupKIOJob( job );
229 }
230 
231 void KNode::ArticleFetchJob::slotResult( KJob * job )
232 {
233  if ( job->error() )
234  setError( job->error(), job->errorString() );
235  else {
236  KNRemoteArticle::Ptr target = boost::static_pointer_cast<KNRemoteArticle>( data() );
237  KIO::StoredTransferJob *j = static_cast<KIO::StoredTransferJob*>( job );
238  QByteArray buffer = j->data();
239  buffer.replace( "\r\n", "\n" ); // TODO: do this in the io-slave?
240  target->setContent( buffer );
241  if ( mParseArticle )
242  target->parse();
243  }
244 
245  emitFinished();
246 }
247 
248 
249 
250 KNode::ArticlePostJob::ArticlePostJob( KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i ) :
251  KNJobData( JTpostArticle, c, a, i )
252 {
253 }
254 
255 void KNode::ArticlePostJob::execute( )
256 {
257  KNLocalArticle::Ptr target = boost::static_pointer_cast<KNLocalArticle>( data() );
258 
259  KUrl url = baseUrl();
260 
261  KIO::Job* job = KIO::storedPut( target->encodedContent( true ), url, -1, KIO::Overwrite | KIO::HideProgressInfo );
262  connect( job, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)) );
263  setupKIOJob( job );
264 }
265 
266 void KNode::ArticlePostJob::slotResult( KJob * job )
267 {
268  if ( job->error() ) {
269  QString hostname = job->errorText();
270  switch ( job->error() ) {
271  case KIO::ERR_WRITE_ACCESS_DENIED:
272  setError( job->error(), i18n( "The server %1 does not allow you to post articles to it.", hostname ) );
273  break;
274  case KIO::ERR_COULD_NOT_WRITE:
275  setError( job->error(), i18n( "The posting of this article to the server %1 failed.\n"
276  "Please check that you are not trying to post to a read-only group.", hostname ) );
277  break;
278  default:
279  setError( job->error(), job->errorString() );
280  }
281  }
282 
283  emitFinished();
284 }
285 
286 #include "nntpjobs.moc"
KNLocalArticle::Ptr
boost::shared_ptr< KNLocalArticle > Ptr
Shared pointer to a KNLocalArticle. To be used instead of raw KNLocalArticle*.
Definition: knarticle.h:214
KNGroup::moderated
Definition: kngroup.h:50
KNGroup::Status
Status
The posting rights status of this group.
Definition: kngroup.h:50
KNRemoteArticle::parse
virtual void parse()
Definition: knarticle.cpp:92
KNGroupListData::Ptr
boost::shared_ptr< KNGroupListData > Ptr
Shared pointer to a KNGroupListData.
Definition: kngroupmanager.h:59
KNJobData
Abstract base class for all KNode internal jobs.
Definition: knjobdata.h:101
kngroupmanager.h
KNGroup
Representation of a news group.
Definition: kngroup.h:41
kngroup.h
nntpjobs.h
KNGroup::setLastFetchCount
void setLastFetchCount(int i)
Definition: kngroup.h:90
KNLocalArticle
This class encapsulates an article, that is stored locally in an MBOX-file.
Definition: knarticle.h:210
KNode::GroupListJob::execute
virtual void execute()
Performs the actual operation of a job, needs to be reimplemented for every job.
Definition: nntpjobs.cpp:28
KNGroup::readOnly
Definition: kngroup.h:50
KNGroup::postingAllowed
Definition: kngroup.h:50
KNode::GroupLoadJob::GroupLoadJob
GroupLoadJob(KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i)
Definition: nntpjobs.cpp:118
KNGroup::unknown
Definition: kngroup.h:50
KNode::GroupLoadJob::execute
virtual void execute()
Performs the actual operation of a job, needs to be reimplemented for every job.
Definition: nntpjobs.cpp:123
KNode::ArticlePostJob::ArticlePostJob
ArticlePostJob(KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i)
Definition: nntpjobs.cpp:250
KNode::ArticleFetchJob::execute
virtual void execute()
Performs the actual operation of a job, needs to be reimplemented for every job.
Definition: nntpjobs.cpp:209
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
KNGroupListData
Data of group list jobs.
Definition: kngroupmanager.h:53
KNRemoteArticle::Ptr
boost::shared_ptr< KNRemoteArticle > Ptr
Shared pointer to a KNRemoteArticle. To be used instead of raw KNRemoteArticle*.
Definition: knarticle.h:107
KNode::ArticleFetchJob::ArticleFetchJob
ArticleFetchJob(KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool parse=true)
Definition: nntpjobs.cpp:203
KNode::ArticleListJob::execute
virtual void execute()
Performs the actual operation of a job, needs to be reimplemented for every job.
Definition: nntpjobs.cpp:143
KNode::ArticlePostJob::execute
virtual void execute()
Performs the actual operation of a job, needs to be reimplemented for every job.
Definition: nntpjobs.cpp:255
KNRemoteArticle
KNRemoteArticle represents an article, whos body has to be retrieved from a remote host or from the l...
Definition: knarticle.h:103
KNServerInfo::Ptr
boost::shared_ptr< KNServerInfo > Ptr
Shared pointer to a KNServerInfo.
Definition: knserverinfo.h:37
KNode::ArticleListJob::ArticleListJob
ArticleListJob(KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool silent=false)
Definition: nntpjobs.cpp:137
KNGroupInfo
Helper classes for the group selection dialog, contains info about a newsgroup (name, description)
Definition: kngroupmanager.h:34
KJob
KNode::GroupListJob::GroupListJob
GroupListJob(KNJobConsumer *c, KNServerInfo::Ptr a, KNJobItem::Ptr i, bool incremental=false)
Definition: nntpjobs.cpp:22
KNGroup::Ptr
boost::shared_ptr< KNGroup > Ptr
Shared pointer to a KNGroup.
Definition: kngroup.h:47
knserverinfo.h
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