[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/pim/krss/resource
From:       Dmitry Ivanov <vonami () gmail ! com>
Date:       2008-08-14 7:13:49
Message-ID: 1218698029.454010.24923.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 846793 by divanov:

Proper private implementation + relay Syndication errors


 M  +2 -2      rssresource.cpp  
 M  +75 -47    syncfeedjob.cpp  
 M  +23 -16    syncfeedjob.h  


--- trunk/playground/pim/krss/resource/rssresource.cpp #846792:846793
@@ -371,7 +371,7 @@
 {
     kDebug() << "Blocked sync done";
 
-    FeedCollection feed = static_cast<SyncFeedJob *>( job )->collection();
+    FeedCollection feed = static_cast<SyncFeedJob *>( job )->feed();
     if ( job->error() ) {
         kWarning() << "Failed to sync the feed";
         kWarning() << job->errorString();
@@ -389,7 +389,7 @@
 {
     kDebug() << "Parallel sync done";
 
-    FeedCollection feed = static_cast<SyncFeedJob *>( job )->collection();
+    FeedCollection feed = static_cast<SyncFeedJob *>( job )->feed();
     if ( job->error() ) {
         kWarning() << "Failed to sync the feed";
         kWarning() << job->errorString();
--- trunk/playground/pim/krss/resource/syncfeedjob.cpp #846792:846793
@@ -17,20 +17,20 @@
 
 #include "syncfeedjob.h"
 #include "flagsmodifyjob.h"
-#include "libkrss/feedpropertiescollectionattribute.h"
 #include "rssitemsync.h"
 
 #include "libkrss/item.h"
 #include "libkrss/person.h"
 #include "libkrss/enclosure.h"
 #include "libkrss/category.h"
+
 #include <KUrl>
 #include <KDebug>
 #include <KDateTime>
 #include <KLocale>
 #include <syndication/dataretriever.h>
 
-#include <QTimer>
+#include <QtCore/QTimer>
 
 using namespace KRss;
 
@@ -118,71 +118,61 @@
     return kfeedItem;
 }
 
-SyncFeedJob::SyncFeedJob( const Akonadi::Collection &collection, QObject *parent ) :
-    KJob( parent ), m_collection( collection )
+// private implementation
+class SyncFeedJobPrivate
 {
-}
+public:
 
-SyncFeedJob::~SyncFeedJob()
-{
-}
+    explicit SyncFeedJobPrivate( SyncFeedJob * const qq, const FeedCollection \
&feedCollection ) +        : q( qq ), m_feed( feedCollection )
+    {
+    }
 
-Akonadi::Collection SyncFeedJob::collection() const
-{
-    return m_collection;
-}
+    void doStart();
+    void slotClearNewDone( KJob* );
+    void slotFetchDone( Syndication::Loader *loader, Syndication::FeedPtr feed, \
Syndication::ErrorCode status ); +    void slotSyncDone( KJob *job );
+    void slotProgress( unsigned long percentage );
 
-void SyncFeedJob::start()
-{
-    QTimer::singleShot( 0, this, SLOT( doStart() ) );
-}
+public:
 
-QString SyncFeedJob::errorString() const
-{
-    switch ( error() ) {
-        case FeedFetchFailed:
-            return i18n( "Failed to load the feed from: %1",
-                         \
                m_collection.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() \
                );
-        case ItemSyncFailed:
-            return errorText();
-        default:
-            return KJob::errorString();
-    }
-}
+    SyncFeedJob * const q;
+    const FeedCollection m_feed;
+};
 
-void SyncFeedJob::doStart()
+void SyncFeedJobPrivate::doStart()
 {
-    FlagsModifyJob *job = new FlagsModifyJob( m_collection, this );
+    FlagsModifyJob *job = new FlagsModifyJob( m_feed, q );
     job->clearFlags( Akonadi::Item::Flags() << "\\Recent" );
-    connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotClearNewDone( KJob* ) ) \
); +    QObject::connect( job, SIGNAL( result( KJob* ) ), q, SLOT( slotClearNewDone( \
KJob* ) ) );  }
 
-void SyncFeedJob::slotClearNewDone( KJob *job )
+void SyncFeedJobPrivate::slotClearNewDone( KJob *job )
 {
     if ( job->error() ) {
         kWarning() << "Failed to clear the 'New' flag on the items";
         kWarning() << "Loading feed anyway";
     }
 
-    Syndication::Loader *loader = Syndication::Loader::create( this, SLOT( \
slotFetchDone( Syndication::Loader*, +    Syndication::Loader *loader = \
                Syndication::Loader::create( q, SLOT( slotFetchDone( \
                Syndication::Loader*,
                                                                                      \
                Syndication::FeedPtr,
                                                                                      \
Syndication::ErrorCode ) ) );  
-    kDebug() << "Url:" << \
m_collection.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl(); +    kDebug() \
<< "Url:" << m_feed.xmlUrl();  Syndication::DataRetriever *dr = new \
                Syndication::FileRetriever();
-    connect( dr, SIGNAL( percent( unsigned long ) ), this, SLOT( slotProgress( \
                unsigned long ) ) );
-    loader->loadFrom( KUrl( \
m_collection.attribute<FeedPropertiesCollectionAttribute>()->xmlUrl() ), dr ); +    \
QObject::connect( dr, SIGNAL( percent( unsigned long ) ), q, SLOT( slotProgress( \
unsigned long ) ) ); +    loader->loadFrom( KUrl( m_feed.xmlUrl() ), dr );
 }
 
-void SyncFeedJob::slotFetchDone( Syndication::Loader *loader, Syndication::FeedPtr \
feed, Syndication::ErrorCode status ) +void SyncFeedJobPrivate::slotFetchDone( \
Syndication::Loader *loader, Syndication::FeedPtr feed, Syndication::ErrorCode status \
)  {
     Q_UNUSED( loader )
 
     kDebug() << "Status:" << status;
 
     if ( status != Syndication::Success ) {
-        setError( FeedFetchFailed );
-        emitResult();
+        q->setError( SyncFeedJob::Aborted -1 + status );
+        q->emitResult();
         return;
     }
 
@@ -195,24 +185,62 @@
         items.append( item );
     }
 
-    Akonadi::ItemSync *syncer = new RssItemSync( m_collection );
-    connect( syncer, SIGNAL( result( KJob* ) ), this, SLOT( slotSyncDone( KJob* ) ) \
); +    Akonadi::ItemSync *syncer = new RssItemSync( m_feed, q );
+    QObject::connect( syncer, SIGNAL( result( KJob* ) ), q, SLOT( slotSyncDone( \
KJob* ) ) );  syncer->setIncrementalSyncItems( items, Akonadi::Item::List() );
 }
 
-void SyncFeedJob::slotSyncDone( KJob *job )
+void SyncFeedJobPrivate::slotSyncDone( KJob *job )
 {
     if ( job->error() ) {
-        setError( ItemSyncFailed );
-        setErrorText( job->errorString() );
+        q->setError( SyncFeedJob::ItemSyncFailed );
+        q->setErrorText( job->errorString() );
     }
 
-    emitResult();
+    q->emitResult();
 }
 
-void SyncFeedJob::slotProgress( unsigned long percentage )
+void SyncFeedJobPrivate::slotProgress( unsigned long percentage )
 {
-    emit progress( m_collection.id(), percentage );
+    emit q->progress( m_feed.id(), percentage );
 }
 
+// public interface implementation
+SyncFeedJob::SyncFeedJob( const FeedCollection &feed, QObject *parent ) :
+    KJob( parent ), d( new SyncFeedJobPrivate( this, feed ) )
+{
+}
+
+SyncFeedJob::~SyncFeedJob()
+{
+    delete d;
+}
+
+FeedCollection SyncFeedJob::feed() const
+{
+    return d->m_feed;
+}
+
+void SyncFeedJob::start()
+{
+    QTimer::singleShot( 0, this, SLOT( doStart() ) );
+}
+
+QString SyncFeedJob::errorString() const
+{
+    switch ( error() ) {
+        // Error strings shamelessly taken from Syndication API docs
+        case Aborted:               return i18n( "File downloading/parsing was \
aborted." ); +        case Timeout:               return i18n( "File download timed \
out." ); +        case UnknownHost:           return i18n( "The hostname couldn't get \
resolved to an IP address." ); +        case FileNotFound:          return i18n( "The \
host was contacted successfully, but reported a 404 error." ); +        case \
OtherRetrieverError:   return i18n( "Retriever error not covered by the error codes \
above." ); +        case InvalidXml:            return i18n( "The XML is invalid." );
+        case XmlNotAccepted:        return i18n( "The source is valid XML, but no \
parser accepted it." ); +        case InvalidFormat:         return i18n( "The source \
was accepted by a parser, but the actual parsing failed." ); +        case \
ItemSyncFailed:        return errorText(); +        default:                    \
return KJob::errorString(); +    }
+}
+
 #include "syncfeedjob.moc"
--- trunk/playground/pim/krss/resource/syncfeedjob.h #846792:846793
@@ -15,31 +15,38 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef KRSS_SYNCFEEDJOB_H
-#define KRSS_SYNCFEEDJOB_H
+#ifndef KRSSRESOURCE_SYNCFEEDJOB_H
+#define KRSSRESOURCE_SYNCFEEDJOB_H
 
 #include "libkrss/feedcollection.h"
 
 #include <syndication/syndication.h>
 #include <KJob>
-#include <akonadi/collection.h>
 
 class SyncFeedJob : public KJob
 {
     Q_OBJECT
 
 public:
+
     enum Error {
-        FeedFetchFailed = KJob::UserDefinedError,
+        Aborted = KJob::UserDefinedError,
+        Timeout,
+        UnknownHost,
+        FileNotFound,
+        OtherRetrieverError,
+        InvalidXml,
+        XmlNotAccepted,
+        InvalidFormat,
         ItemSyncFailed
     };
 
 public:
 
-    explicit SyncFeedJob( const Akonadi::Collection &collection, QObject *parent = 0 \
); +    explicit SyncFeedJob( const KRss::FeedCollection &feed, QObject *parent = 0 \
);  ~SyncFeedJob();
 
-    Akonadi::Collection collection() const;
+    KRss::FeedCollection feed() const;
 
     void start();
     QString errorString() const;
@@ -48,17 +55,17 @@
 
     void progress( KRss::FeedCollection::Id id, unsigned long percentage );
 
-private Q_SLOTS:
+private:
 
-    void doStart();
-    void slotClearNewDone( KJob* );
-    void slotFetchDone( Syndication::Loader *loader, Syndication::FeedPtr feed, \
                Syndication::ErrorCode status );
-    void slotSyncDone( KJob *job );
-    void slotProgress( unsigned long percentage );
+    friend class SyncFeedJobPrivate;
+    class SyncFeedJobPrivate * const d;
 
-private:
-
-    Akonadi::Collection m_collection;
+    Q_DISABLE_COPY( SyncFeedJob )
+    Q_PRIVATE_SLOT( d, void doStart() )
+    Q_PRIVATE_SLOT( d, void slotClearNewDone( KJob* ) )
+    Q_PRIVATE_SLOT( d, void slotFetchDone( Syndication::Loader *loader, \
Syndication::FeedPtr feed, Syndication::ErrorCode status ) ) +    Q_PRIVATE_SLOT( d, \
void slotSyncDone( KJob *job ) ) +    Q_PRIVATE_SLOT( d, void slotProgress( unsigned \
long percentage ) )  };
 
-#endif /* KRSS_SYNCFEEDJOB_H */
+#endif // KRSSRESOURCE_SYNCFEEDJOB_H


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic