[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepim-runtime/akregator_port] krsslocal: Fix indentation, remove some file.close() calls.
From: Frank Osterfeld <frank.osterfeld () kdab ! com>
Date: 2012-03-31 15:16:47
Message-ID: 20120331151647.39349A60D1 () git ! kde ! org
[Download RAW message or body]
Git commit 2e58ef765d14280223127033e6dee66c359efa6a by Frank Osterfeld.
Committed on 26/02/2012 at 19:15.
Pushed by osterfeld into branch 'akregator_port'.
Fix indentation, remove some file.close() calls.
M +113 -131 krsslocal/krsslocalresource.cpp
http://commits.kde.org/kdepim-runtime/2e58ef765d14280223127033e6dee66c359efa6a
diff --git a/krsslocal/krsslocalresource.cpp b/krsslocal/krsslocalresource.cpp
index c6ff705..7f6cce9 100644
--- a/krsslocal/krsslocalresource.cpp
+++ b/krsslocal/krsslocalresource.cpp
@@ -48,56 +48,53 @@ using namespace boost;
KRssLocalResource::KRssLocalResource( const QString &id )
: ResourceBase( id ), m_syncer( 0 )
{
- new SettingsAdaptor( Settings::self() );
- QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
+ new SettingsAdaptor( Settings::self() );
+ QDBusConnection::sessionBus().registerObject( QLatin1String( "/Settings" ),
Settings::self(), QDBusConnection::ExportAdaptors );
- //policy.setCacheTimeout( CACHE_TIMEOUT );
- //policy.setIntervalCheckTime( INTERVAL_CHECK_TIME );
+ //policy.setCacheTimeout( CACHE_TIMEOUT );
+ //policy.setIntervalCheckTime( INTERVAL_CHECK_TIME );
- AttributeFactory::registerAttribute<KRss::FeedPropertiesCollectionAttribute>();
+ AttributeFactory::registerAttribute<KRss::FeedPropertiesCollectionAttribute>();
- policy.setInheritFromParent( false );
- policy.setSyncOnDemand( false );
- policy.setLocalParts( QStringList() << KRss::Item::HeadersPart << \
KRss::Item::ContentPart << Akonadi::Item::FullPayload );
-
-
- //changeRecorder()->fetchCollection( true );
-
- changeRecorder()->itemFetchScope().fetchFullPayload( false );
- //changeRecorder()->itemFetchScope().fetchAllAttributes( true );
-
- //This timer handles the situation in which at least one collection is changed
- //and the modifications must be written back on the opml file.
- //
- writeBackTimer = new QTimer(this);
- writeBackTimer->setSingleShot( true );
- connect(writeBackTimer, SIGNAL(timeout()), this, SIGNAL(quitOrTimeout()));
- connect(this, SIGNAL(quitOrTimeout()), this, SLOT(fetchCollections()));
-
+ policy.setInheritFromParent( false );
+ policy.setSyncOnDemand( false );
+ policy.setLocalParts( QStringList() << KRss::Item::HeadersPart << \
KRss::Item::ContentPart << Akonadi::Item::FullPayload ); +
+
+ //changeRecorder()->fetchCollection( true );
+
+ changeRecorder()->itemFetchScope().fetchFullPayload( false );
+ //changeRecorder()->itemFetchScope().fetchAllAttributes( true );
+
+ //This timer handles the situation in which at least one collection is changed
+ //and the modifications must be written back on the opml file.
+ //
+ writeBackTimer = new QTimer(this);
+ writeBackTimer->setSingleShot( true );
+ connect(writeBackTimer, SIGNAL(timeout()), this, SIGNAL(quitOrTimeout()));
+ connect(this, SIGNAL(quitOrTimeout()), this, SLOT(fetchCollections()));
}
KRssLocalResource::~KRssLocalResource()
{
- delete writeBackTimer;
}
QString KRssLocalResource::mimeType()
{
- return QLatin1String("application/rss+xml");
+ return QLatin1String("application/rss+xml");
}
void KRssLocalResource::retrieveCollections()
{
-
const QString path = Settings::self()->path();
/* We'll parse the opml file */
QFile file( path );
/* If we can't open it, let's show an error message. */
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- error(i18n("Could not open %1: %2", path, file.errorString()) );
- return;
+ error(i18n("Could not open %1: %2", path, file.errorString()) );
+ return;
}
QXmlStreamReader reader( &file );
@@ -139,9 +136,6 @@ void KRssLocalResource::retrieveCollections()
list = buildCollectionTree(parser.topLevelNodes(), list, top);
collectionsRetrieved( list );
-
- file.close();
-
}
Collection::List KRssLocalResource::buildCollectionTree( QList<shared_ptr<const \
ParsedNode> > listOfNodes, @@ -150,28 +144,27 @@ Collection::List \
KRssLocalResource::buildCollectionTree( QList<shared_ptr<const list << parent;
foreach(const shared_ptr<const ParsedNode> parsedNode, listOfNodes) {
- if (!parsedNode->isFolder()) {
- Collection c = (static_pointer_cast<const \
ParsedFeed>(parsedNode))->toAkonadiCollection();
- c.attribute<Akonadi::EntityDisplayAttribute>( Collection::AddIfMissing \
)->setDisplayName( parsedNode->title() );
- c.setContentMimeTypes( c.contentMimeTypes() );
- c.setParent( parent );
- c.setCachePolicy( policy );
-
- //it customizes the collection with an rss icon
- c.attribute<Akonadi::EntityDisplayAttribute>( Collection::AddIfMissing \
)->setIconName( QString("application-rss+xml") );
-
- list << c;
- }
- else {
- shared_ptr<const ParsedFolder> parsedFolder = static_pointer_cast<const \
ParsedFolder>(parsedNode);
- Collection folder;
- folder.setParent( parent );
- folder.setName( i18n("T_%1", parsedFolder->title()) );
- folder.attribute<Akonadi::EntityDisplayAttribute>( \
Collection::AddIfMissing )->setDisplayName( parsedFolder->title() );
- folder.setRemoteId( Settings::self()->path() + parsedFolder->title() );
- folder.setContentMimeTypes( QStringList( Collection::mimeType() ) );
- list = buildCollectionTree( parsedFolder->children(), list, folder );
- }
+ if (!parsedNode->isFolder()) {
+ Collection c = (static_pointer_cast<const \
ParsedFeed>(parsedNode))->toAkonadiCollection(); + \
c.attribute<Akonadi::EntityDisplayAttribute>( Collection::AddIfMissing \
)->setDisplayName( parsedNode->title() ); + c.setContentMimeTypes( \
c.contentMimeTypes() ); + c.setParent( parent );
+ c.setCachePolicy( policy );
+
+ //it customizes the collection with an rss icon
+ c.attribute<Akonadi::EntityDisplayAttribute>( Collection::AddIfMissing \
)->setIconName( QString("application-rss+xml") ); +
+ list << c;
+ } else {
+ shared_ptr<const ParsedFolder> parsedFolder = static_pointer_cast<const \
ParsedFolder>(parsedNode); + Collection folder;
+ folder.setParent( parent );
+ folder.setName( i18n("T_%1", parsedFolder->title()) );
+ folder.attribute<Akonadi::EntityDisplayAttribute>( \
Collection::AddIfMissing )->setDisplayName( parsedFolder->title() ); + \
folder.setRemoteId( Settings::self()->path() + parsedFolder->title() ); + \
folder.setContentMimeTypes( QStringList( Collection::mimeType() ) ); + \
list = buildCollectionTree( parsedFolder->children(), list, folder ); + }
}
return list;
@@ -181,7 +174,7 @@ void KRssLocalResource::retrieveItems( const Akonadi::Collection \
&collection ) {
Syndication::Loader * const loader = Syndication::Loader::create();
connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode ) ),
- this, SLOT( slotLoadingComplete( Syndication::Loader*, \
Syndication::FeedPtr, Syndication::ErrorCode ) ) ); + this, SLOT( \
slotLoadingComplete( Syndication::Loader*, Syndication::FeedPtr, \
Syndication::ErrorCode ) ) ); const KRss::FeedCollection fc( collection );
const KUrl xmlUrl = fc.xmlUrl();
m_collectionByLoader.insert( loader, collection );
@@ -220,124 +213,117 @@ void \
KRssLocalResource::slotLoadingComplete(Syndication::Loader* loader, Syndica
//--- a replacement of itemsRetrieved that uses a custom ItemSync---
if (!m_syncer) {
- m_syncer = new RssItemSync( fc );
- connect( m_syncer, SIGNAL(result(KJob*)), this, SLOT(slotItemSyncDone(KJob*)) );
+ m_syncer = new RssItemSync( fc );
+ connect( m_syncer, SIGNAL(result(KJob*)), this, \
SLOT(slotItemSyncDone(KJob*)) ); }
m_syncer->setIncrementalSyncItems( items, Item::List() );
- //------------------------------------------------------------------
-
}
-void KRssLocalResource::slotItemSyncDone( KJob *job ) {
- m_syncer = 0;
- if ( job->error() && job->error() != Job::UserCanceled ) {
- emit error( job->errorString() );
- }
- itemsRetrievalDone();
+void KRssLocalResource::slotItemSyncDone( KJob *job )
+{
+ m_syncer = 0;
+ if ( job->error() && job->error() != Job::UserCanceled )
+ emit error( job->errorString() );
+ itemsRetrievalDone();
}
bool KRssLocalResource::retrieveItem( const Akonadi::Item &item, const \
QSet<QByteArray> &parts ) {
- Q_UNUSED( parts );
-
- itemRetrieved( item );
- return true;
+ Q_UNUSED( parts );
+
+ itemRetrieved( item );
+ return true;
}
void KRssLocalResource::aboutToQuit()
{
- // TODO: any cleanup you need to do while there is still an active
- // event loop. The resource will terminate after this method returns
-
- if (writeBackTimer->isActive()) {
- writeBackTimer->stop();
- emit quitOrTimeout();
- }
-
+ // TODO: any cleanup you need to do while there is still an active
+ // event loop. The resource will terminate after this method returns
+
+ if (writeBackTimer->isActive()) {
+ writeBackTimer->stop();
+ emit quitOrTimeout();
+ }
}
void KRssLocalResource::configure( WId windowId )
{
- Q_UNUSED( windowId );
+ Q_UNUSED( windowId );
- const QString oldPath = Settings::self()->path();
-
- KUrl startUrl;
- if ( oldPath.isEmpty() )
- startUrl = KUrl( QDir::homePath() );
- else
- startUrl = KUrl( oldPath );
-
- const QString title = i18nc("@title:window", "Select an OPML Document");
- QString newPath = KFileDialog::getOpenFileName( startUrl, QLatin1String("*.opml|") \
+ i18n("OPML Document (*.opml)"), + const QString oldPath = \
Settings::self()->path(); +
+ KUrl startUrl;
+ if ( oldPath.isEmpty() )
+ startUrl = KUrl( QDir::homePath() );
+ else
+ startUrl = KUrl( oldPath );
+
+ const QString title = i18nc("@title:window", "Select an OPML Document");
+ QString newPath = KFileDialog::getOpenFileName( startUrl, \
QLatin1String("*.opml|") + i18n("OPML Document (*.opml)"), 0, title );
-
- if ( newPath.isEmpty() )
- newPath = KStandardDirs::locateLocal( "appdata", QLatin1String("feeds.opml") );
-
- Settings::self()->setPath( newPath );
- Settings::self()->writeConfig();
- synchronize();
-
+
+ if ( newPath.isEmpty() )
+ newPath = KStandardDirs::locateLocal( "appdata", QLatin1String("feeds.opml") \
); +
+ Settings::self()->setPath( newPath );
+ Settings::self()->writeConfig();
+ synchronize();
}
void KRssLocalResource::itemAdded( const Akonadi::Item &item, const \
Akonadi::Collection &collection ) {
- Q_UNUSED( collection );
-
- changeCommitted( item );
+ Q_UNUSED( collection );
+
+ changeCommitted( item );
}
void KRssLocalResource::itemRemoved( const Akonadi::Item &item )
{
- changeCommitted( item );
+ changeCommitted( item );
}
void KRssLocalResource::itemChanged( const Akonadi::Item &item, const \
QSet<QByteArray> &parts ) {
- Q_UNUSED( parts );
+ Q_UNUSED( parts );
- changeCommitted( item );
-
+ changeCommitted( item );
}
void KRssLocalResource::collectionChanged(const Akonadi::Collection& collection)
{
+ changeCommitted( collection );
- changeCommitted( collection );
-
- if (!writeBackTimer->isActive()) {
- writeBackTimer->start(WriteBackTimeout);
- }
-
+ if (!writeBackTimer->isActive()) {
+ writeBackTimer->start(WriteBackTimeout);
+ }
}
-void KRssLocalResource::fetchCollections() {
- CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), \
CollectionFetchJob::Recursive, this );
- job->fetchScope().setContentMimeTypes( QStringList() << mimeType() );
- connect( job, SIGNAL( result( KJob* ) ), SLOT( fetchCollectionsFinished( KJob* ) ) \
); +void KRssLocalResource::fetchCollections()
+{
+ CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), \
CollectionFetchJob::Recursive, this ); + job->fetchScope().setContentMimeTypes( \
QStringList() << mimeType() ); + connect( job, SIGNAL( result( KJob* ) ), SLOT( \
fetchCollectionsFinished( KJob* ) ) ); }
-void KRssLocalResource::fetchCollectionsFinished(KJob *job) {
-
- if ( job->error() ) {
- qDebug() << "Error occurred";
- return;
- }
-
- CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
- QList<Collection> collections = fetchJob->collections();
- writeFeedsToOpml( Settings::self()->path(), Util::parsedDescendants( collections, \
Collection::root() ) );
-
+void KRssLocalResource::fetchCollectionsFinished(KJob *job)
+{
+ if ( job->error() )
+ {
+ qDebug() << "Error occurred";
+ return;
+ }
+
+ CollectionFetchJob *fetchJob = qobject_cast<CollectionFetchJob*>( job );
+ QList<Collection> collections = fetchJob->collections();
+ writeFeedsToOpml( Settings::self()->path(), Util::parsedDescendants( \
collections, Collection::root() ) ); }
void KRssLocalResource::writeFeedsToOpml(const QString &path, const \
QList<boost::shared_ptr< const ParsedNode> >& nodes) {
-
KSaveFile file( path );
if ( !file.open( QIODevice::ReadWrite | QIODevice::Text ) ) {
- error( i18n("Could not open %1: %2", path, file.errorString()) );
- return;
+ error( i18n("Could not open %1: %2", path, file.errorString()) );
+ return;
}
QXmlStreamWriter writer( &file );
@@ -347,12 +333,8 @@ void KRssLocalResource::writeFeedsToOpml(const QString &path, \
const QList<boost: writer.writeEndDocument();
if ( !file.finalize() ) {
- error( i18n("Could not save %1: %2", path, file.errorString()) );
+ error( i18n("Could not save %1: %2", path, file.errorString()) );
}
-
- file.close();
- return;
-
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic