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

knode

nntpjobs.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (c) 2005 by Volker Krause <volker.krause@rwth-aachen.de>
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008     You should have received a copy of the GNU General Public License
00009     along with this program; if not, write to the Free Software Foundation,
00010     Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US
00011 */
00012 
00013 #include "nntpjobs.h"
00014 
00015 #include "kngroup.h"
00016 #include "kngroupmanager.h"
00017 #include "knserverinfo.h"
00018 #include <kdebug.h>
00019 #include <klocale.h>
00020 #include <QDir>
00021 
00022 KNode::GroupListJob::GroupListJob( KNJobConsumer * c, KNServerInfo * a, KNJobItem * i, bool incremental ) :
00023   KNJobData( KNJobData::JTFetchGroups, c, a, i ),
00024   mIncremental( incremental )
00025 {
00026 }
00027 
00028 void KNode::GroupListJob::execute()
00029 {
00030   mGroupList.clear();
00031 
00032   KNGroupListData *target = static_cast<KNGroupListData *>( data() );
00033 
00034   KUrl destination = baseUrl();
00035   QStringList query;
00036   if ( target->getDescriptions )
00037     query << "desc=true";
00038   if ( mIncremental )
00039     query << QString( "since=%1%2%3+000000" )
00040         .arg( target->fetchSince.year() % 100, 2, 10, QChar( '0' ) )
00041         .arg( target->fetchSince.month(), 2, 10, QChar( '0' ) )
00042         .arg( target->fetchSince.day(), 2, 10, QChar( '0' ) );
00043   destination.setQuery( query.join( "&" ) );
00044   KIO::Job* job = KIO::listDir( destination, KIO::HideProgressInfo, true );
00045   connect( job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
00046            SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&)) );
00047   connect( job, SIGNAL( result(KJob*) ), SLOT( slotResult(KJob*) ) );
00048   setupKIOJob( job );
00049 }
00050 
00051 void KNode::GroupListJob::slotEntries( KIO::Job * job, const KIO::UDSEntryList & list )
00052 {
00053   Q_UNUSED( job );
00054    KNGroupListData *target = static_cast<KNGroupListData *>( data() );
00055 
00056   QString name, desc;
00057   bool subscribed;
00058   KNGroup::Status access;
00059   for( KIO::UDSEntryList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
00060     access = KNGroup::unknown;
00061     name = (*it).stringValue( KIO::UDSEntry::UDS_NAME );
00062     desc = (*it).stringValue( KIO::UDSEntry::UDS_EXTRA );
00063 
00064     int value = (*it).numberValue( KIO::UDSEntry::UDS_ACCESS, -1 );
00065     if ( value != -1 ) {
00066       if( value & S_IWOTH )
00067         access = KNGroup::postingAllowed;
00068       else if ( value & S_IWGRP )
00069         access = KNGroup::moderated;
00070       else
00071         access = KNGroup::readOnly;
00072     }
00073 
00074     if ( name.isEmpty() )
00075       continue;
00076     if ( target->subscribed.contains( name ) ) {
00077       target->subscribed.removeAll( name );    // group names are unique, we wont find it again anyway...
00078       subscribed = true;
00079     } else {
00080       subscribed = false;
00081     }
00082     kDebug() << "Found group " << name;
00083     if ( mIncremental )
00084       mGroupList.append(KNGroupInfo( name, desc, true, subscribed, access ) );
00085     else
00086       target->groups->append(KNGroupInfo( name, desc, false, subscribed, access ) );
00087   }
00088 }
00089 
00090 void KNode::GroupListJob::slotResult( KJob * job )
00091 {
00092   if ( job->error() )
00093     setError( job->error(), job->errorString() );
00094   else {
00095     KNGroupListData *target = static_cast<KNGroupListData *>( data() );
00096 
00097     // TODO: use thread weaver here?
00098     if ( mIncremental ) {
00099       setStatus( i18n("Loading group list from disk...") );
00100       if ( !target->readIn() ) {
00101         setError( KIO::ERR_COULD_NOT_READ, i18n("Unable to read the group list file") );
00102         emitFinished();
00103         return;
00104       }
00105       target->merge( &mGroupList );
00106     }
00107     setStatus( i18n("Writing group list to disk...") );
00108 
00109     if ( !target->writeOut() )
00110       setError( KIO::ERR_COULD_NOT_WRITE, i18n("Unable to write the group list file") );
00111   }
00112 
00113   emitFinished();
00114 }
00115 
00116 
00117 
00118 KNode::GroupLoadJob::GroupLoadJob( KNJobConsumer * c, KNServerInfo * a, KNJobItem * i ) :
00119   KNJobData( KNJobData::JTLoadGroups, c, a, i )
00120 {
00121 }
00122 
00123 void KNode::GroupLoadJob::execute( )
00124 {
00125   KNGroupListData *target = static_cast<KNGroupListData *>( data() );
00126 
00127   setStatus( i18n("Loading group list from disk...") );
00128   // TODO: use the thread weaver here
00129   if ( !target->readIn() )
00130     setError( KIO::ERR_COULD_NOT_READ, i18n("Unable to read the group list file") );
00131 
00132   emitFinished();
00133 }
00134 
00135 
00136 
00137 KNode::ArticleListJob::ArticleListJob( KNJobConsumer * c, KNServerInfo * a, KNJobItem * i, bool silent ) :
00138     KNJobData( JTfetchNewHeaders, c, a, i ),
00139     mSilent( silent )
00140 {
00141 }
00142 
00143 void KNode::ArticleListJob::execute()
00144 {
00145   mArticleList.clear();
00146 
00147   KNGroup* target = static_cast<KNGroup*>( data() );
00148 
00149   KUrl destination = baseUrl();
00150   destination.setPath( target->groupname() );
00151   QStringList query;
00152   query << "first=" + QString::number( target->lastNr() + 1 );
00153   if ( target->lastNr() <= 0 ) // first fetch
00154     query << "max=" + QString::number( target->maxFetch() );
00155   destination.setQuery( query.join( "&" ) );
00156   KIO::Job* job = KIO::listDir( destination, KIO::HideProgressInfo, true );
00157   connect( job, SIGNAL(entries(KIO::Job*, const KIO::UDSEntryList&)),
00158            SLOT(slotEntries(KIO::Job*, const KIO::UDSEntryList&)) );
00159   connect( job, SIGNAL( result(KJob*) ), SLOT( slotResult(KJob*) ) );
00160   setupKIOJob( job );
00161 }
00162 
00163 void KNode::ArticleListJob::slotEntries( KIO::Job * job, const KIO::UDSEntryList & list )
00164 {
00165   Q_UNUSED( job );
00166   mArticleList += list;
00167 }
00168 
00169 void KNode::ArticleListJob::slotResult( KJob * _job )
00170 {
00171   Q_ASSERT( mJob == _job );
00172   KIO::Job *job = static_cast<KIO::Job*>( _job );
00173   if ( job->error() )
00174     setError( job->error(), job->errorString() );
00175   else {
00176     KNGroup* target = static_cast<KNGroup*>( data() );
00177     target->setLastFetchCount( 0 );
00178 
00179     setStatus( i18n("Sorting...") );
00180 
00181     if ( job->metaData().contains( "FirstSerialNumber" ) ) {
00182       int firstSerNum = job->metaData()["FirstSerialNumber"].toInt();
00183       target->setFirstNr( firstSerNum );
00184     }
00185 
00186     target->insortNewHeaders( mArticleList );
00187 
00188     if ( job->metaData().contains( "LastSerialNumber" ) ) {
00189       int lastSerNum = job->metaData()["LastSerialNumber"].toInt();
00190       target->setLastNr( lastSerNum );
00191     }
00192   }
00193 
00194   emitFinished();
00195 }
00196 
00197 
00198 
00199 KNode::ArticleFetchJob::ArticleFetchJob( KNJobConsumer * c, KNServerInfo * a, KNJobItem * i, bool parse ) :
00200     KNJobData( JTfetchArticle, c, a, i ),
00201     mParseArticle( parse )
00202 {
00203 }
00204 
00205 void KNode::ArticleFetchJob::execute()
00206 {
00207   KNRemoteArticle *target = static_cast<KNRemoteArticle*>( data() );
00208   QString path = static_cast<KNGroup*>( target->collection() )->groupname();
00209 
00210   KUrl url = baseUrl();
00211   path += QDir::separator();
00212   path += target->messageID()->as7BitString( false );
00213   url.setPath( path );
00214 
00215   KIO::Job* job = KIO::storedGet( url, KIO::NoReload, KIO::HideProgressInfo );
00216   connect( job, SIGNAL( result(KJob*) ), SLOT( slotResult(KJob*) ) );
00217   setupKIOJob( job );
00218 }
00219 
00220 void KNode::ArticleFetchJob::slotResult( KJob * job )
00221 {
00222   if ( job->error() )
00223     setError( job->error(), job->errorString() );
00224   else {
00225     KNRemoteArticle *target = static_cast<KNRemoteArticle*>( data() );
00226     KIO::StoredTransferJob *j = static_cast<KIO::StoredTransferJob*>( job );
00227     QByteArray buffer = j->data();
00228     buffer.replace( "\r\n", "\n" ); // TODO: do this in the io-slave?
00229     target->setContent( buffer );
00230     if ( mParseArticle )
00231       target->parse();
00232   }
00233 
00234   emitFinished();
00235 }
00236 
00237 
00238 
00239 KNode::ArticlePostJob::ArticlePostJob( KNJobConsumer * c, KNServerInfo * a, KNJobItem * i ) :
00240     KNJobData( JTpostArticle, c, a, i )
00241 {
00242 }
00243 
00244 void KNode::ArticlePostJob::execute( )
00245 {
00246   KNLocalArticle *target = static_cast<KNLocalArticle*>( data() );
00247 
00248   KUrl url = baseUrl();
00249 
00250   KIO::Job* job = KIO::storedPut( target->encodedContent( true ), url, -1, KIO::Overwrite | KIO::HideProgressInfo );
00251   connect( job, SIGNAL( result(KJob*) ), SLOT( slotResult(KJob*) ) );
00252   setupKIOJob( job );
00253 }
00254 
00255 void KNode::ArticlePostJob::slotResult( KJob * job )
00256 {
00257   if ( job->error() )
00258     setError( job->error(), job->errorString() );
00259 
00260   emitFinished();
00261 }
00262 
00263 #include "nntpjobs.moc"

knode

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal