From kde-commits Sat Mar 31 15:16:47 2012 From: Frank Osterfeld Date: Sat, 31 Mar 2012 15:16:47 +0000 To: kde-commits Subject: [kdepim-runtime/akregator_port] krsslocal: Fix indentation, remove some file.close() calls. Message-Id: <20120331151647.39349A60D1 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133320773707783 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/2e58ef765d14280223127033e6dee66c359ef= a6a 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( "/Setting= s" ), Settings::self(), QDBusConnection::ExportAdapt= ors ); = - //policy.setCacheTimeout( CACHE_TIMEOUT ); - //policy.setIntervalCheckTime( INTERVAL_CHECK_TIME ); + //policy.setCacheTimeout( CACHE_TIMEOUT ); + //policy.setIntervalCheckTime( INTERVAL_CHECK_TIME ); = - AttributeFactory::registerAttribute(); + AttributeFactory::registerAttribute(); = - 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 c= hanged - //and the modifications must be written back on the opml file. - // - writeBackTimer =3D 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 =3D 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 =3D 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 =3D buildCollectionTree(parser.topLevelNodes(), list, top); = = collectionsRetrieved( list ); - = - file.close(); - } = Collection::List KRssLocalResource::buildCollectionTree( QList > listOfNodes, = @@ -150,28 +144,27 @@ Collection::List KRssLocalResource::buildCollectionTr= ee( QList parsedNode, listOfNodes) { - if (!parsedNode->isFolder()) { - Collection c =3D (static_pointer_cast(parsedNode))-= >toAkonadiCollection(); - c.attribute( Collection::AddIfMissin= g )->setDisplayName( parsedNode->title() ); - c.setContentMimeTypes( c.contentMimeTypes() ); - c.setParent( parent ); - c.setCachePolicy( policy ); - = - //it customizes the collection with an rss icon - c.attribute( Collection::AddIfMissin= g )->setIconName( QString("application-rss+xml") ); - = - list << c; - } - else { - shared_ptr parsedFolder =3D static_pointer_cast(parsedNode); - Collection folder; - folder.setParent( parent ); - folder.setName( i18n("T_%1", parsedFolder->title()) ); - folder.attribute( Collection:= :AddIfMissing )->setDisplayName( parsedFolder->title() ); - folder.setRemoteId( Settings::self()->path() + parsedFolder->title() = ); - folder.setContentMimeTypes( QStringList( Collection::mimeType() ) ); - list =3D buildCollectionTree( parsedFolder->children(), list, folder = ); - } + if (!parsedNode->isFolder()) { + Collection c =3D (static_pointer_cast(parsed= Node))->toAkonadiCollection(); + c.attribute( Collection::AddI= fMissing )->setDisplayName( parsedNode->title() ); + c.setContentMimeTypes( c.contentMimeTypes() ); + c.setParent( parent ); + c.setCachePolicy( policy ); + + //it customizes the collection with an rss icon + c.attribute( Collection::AddI= fMissing )->setIconName( QString("application-rss+xml") ); + + list << c; + } else { + shared_ptr parsedFolder =3D static_pointer= _cast(parsedNode); + Collection folder; + folder.setParent( parent ); + folder.setName( i18n("T_%1", parsedFolder->title()) ); + folder.attribute( Collect= ion::AddIfMissing )->setDisplayName( parsedFolder->title() ); + folder.setRemoteId( Settings::self()->path() + parsedFolder->t= itle() ); + folder.setContentMimeTypes( QStringList( Collection::mimeType(= ) ) ); + list =3D buildCollectionTree( parsedFolder->children(), list, = folder ); + } } = return list; @@ -181,7 +174,7 @@ void KRssLocalResource::retrieveItems( const Akonadi::C= ollection &collection ) { = Syndication::Loader * const loader =3D Syndication::Loader::create(); connect( loader, SIGNAL( loadingComplete( Syndication::Loader*, Syndic= ation::FeedPtr, Syndication::ErrorCode ) ), - this, SLOT( slotLoadingComplete( Syndication::Loader*, Syndica= tion::FeedPtr, Syndication::ErrorCode ) ) ); + this, SLOT( slotLoadingComplete( Syndication::Loader*, Syndic= ation::FeedPtr, Syndication::ErrorCode ) ) ); const KRss::FeedCollection fc( collection ); const KUrl xmlUrl =3D fc.xmlUrl(); m_collectionByLoader.insert( loader, collection ); @@ -220,124 +213,117 @@ void KRssLocalResource::slotLoadingComplete(Syndica= tion::Loader* loader, Syndica = //--- a replacement of itemsRetrieved that uses a custom ItemSync--- if (!m_syncer) { - m_syncer =3D new RssItemSync( fc ); - connect( m_syncer, SIGNAL(result(KJob*)), this, SLOT(slotItemSyncDone(KJo= b*)) ); + m_syncer =3D new RssItemSync( fc ); + connect( m_syncer, SIGNAL(result(KJob*)), this, SLOT(slotItemSyncD= one(KJob*)) ); } m_syncer->setIncrementalSyncItems( items, Item::List() ); - //------------------------------------------------------------------ - = } = -void KRssLocalResource::slotItemSyncDone( KJob *job ) { - m_syncer =3D 0; - if ( job->error() && job->error() !=3D Job::UserCanceled ) { - emit error( job->errorString() ); - } - itemsRetrievalDone(); +void KRssLocalResource::slotItemSyncDone( KJob *job ) +{ + m_syncer =3D 0; + if ( job->error() && job->error() !=3D Job::UserCanceled ) + emit error( job->errorString() ); + itemsRetrievalDone(); } = bool KRssLocalResource::retrieveItem( const Akonadi::Item &item, const QSe= t &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 =3D Settings::self()->path(); - = - KUrl startUrl; - if ( oldPath.isEmpty() ) - startUrl =3D KUrl( QDir::homePath() ); - else - startUrl =3D KUrl( oldPath ); - - const QString title =3D i18nc("@title:window", "Select an OPML Document"= ); - QString newPath =3D KFileDialog::getOpenFileName( startUrl, QLatin1Strin= g("*.opml|") + i18n("OPML Document (*.opml)"), + const QString oldPath =3D Settings::self()->path(); + + KUrl startUrl; + if ( oldPath.isEmpty() ) + startUrl =3D KUrl( QDir::homePath() ); + else + startUrl =3D KUrl( oldPath ); + + const QString title =3D i18nc("@title:window", "Select an OPML Documen= t"); + QString newPath =3D KFileDialog::getOpenFileName( startUrl, QLatin1Str= ing("*.opml|") + i18n("OPML Document (*.opml)"), 0, title ); - = - if ( newPath.isEmpty() ) - newPath =3D KStandardDirs::locateLocal( "appdata", QLatin1String("feed= s.opml") ); - = - Settings::self()->setPath( newPath ); - Settings::self()->writeConfig(); - synchronize(); - = + + if ( newPath.isEmpty() ) + newPath =3D KStandardDirs::locateLocal( "appdata", QLatin1String("= feeds.opml") ); + + Settings::self()->setPath( newPath ); + Settings::self()->writeConfig(); + synchronize(); } = void KRssLocalResource::itemAdded( const Akonadi::Item &item, const Akonad= i::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= &parts ) { - Q_UNUSED( parts ); + Q_UNUSED( parts ); = - changeCommitted( item ); - = + changeCommitted( item ); } = void KRssLocalResource::collectionChanged(const Akonadi::Collection& colle= ction) { = + changeCommitted( collection ); = - changeCommitted( collection ); - = - if (!writeBackTimer->isActive()) { - writeBackTimer->start(WriteBackTimeout); - } - = + if (!writeBackTimer->isActive()) { + writeBackTimer->start(WriteBackTimeout); + } } = -void KRssLocalResource::fetchCollections() { - CollectionFetchJob *job =3D 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 =3D new CollectionFetchJob( Collection::root()= , CollectionFetchJob::Recursive, this ); + job->fetchScope().setContentMimeTypes( QStringList() << mimeType() ); + connect( job, SIGNAL( result( KJob* ) ), SLOT( fetchCollectionsFinishe= d( KJob* ) ) ); } = -void KRssLocalResource::fetchCollectionsFinished(KJob *job) { - = - if ( job->error() ) { - qDebug() << "Error occurred"; - return; - } - - CollectionFetchJob *fetchJob =3D qobject_cast( job= ); - QList collections =3D fetchJob->collections(); - writeFeedsToOpml( Settings::self()->path(), Util::parsedDescendants( co= llections, Collection::root() ) ); - = +void KRssLocalResource::fetchCollectionsFinished(KJob *job) +{ + if ( job->error() ) + { + qDebug() << "Error occurred"; + return; + } + + CollectionFetchJob *fetchJob =3D qobject_cast( jo= b ); + QList collections =3D fetchJob->collections(); + writeFeedsToOpml( Settings::self()->path(), Util::parsedDescendants( c= ollections, 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