[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kdepimlibs/akregator_port] krss: port away from TreeNode and FeedList
From: Christophe Giboudeaux <cgiboudeaux () gmx ! com>
Date: 2012-03-31 15:16:23
Message-ID: 20120331151623.C62D6A60E0 () git ! kde ! org
[Download RAW message or body]
Git commit 3195a1a86fe921abb6111e29283ddf0ae5df2716 by Christophe Giboudeaux, on \
behalf of Frank Osterfeld. Committed on 18/09/2011 at 01:18.
Pushed by osterfeld into branch 'akregator_port'.
port away from TreeNode and FeedList
(cherry picked from commit 89b393ced08c26c8613505b523e7dd7fd883dce8)
Conflicts:
akregator/src/abstractselectioncontroller.h
akregator/src/articleformatter.cpp
akregator/src/articleformatter.h
akregator/src/articleviewer.cpp
akregator/src/articleviewer.h
akregator/src/mainwidget.cpp
akregator/src/selectioncontroller.cpp
akregator/src/selectioncontroller.h
M +0 -6 krss/CMakeLists.txt
M +0 -2 krss/feeditemmodel.cpp
D +0 -696 krss/feedlistmodel.cpp
D +0 -94 krss/feedlistmodel.h
D +0 -214 krss/itemmodel.cpp
D +0 -87 krss/itemmodel.h
D +0 -643 krss/standardactionmanager.cpp
D +0 -113 krss/standardactionmanager.h
http://commits.kde.org/kdepimlibs/3195a1a86fe921abb6111e29283ddf0ae5df2716
diff --git a/krss/CMakeLists.txt b/krss/CMakeLists.txt
index f7e536b..0d17f5f 100644
--- a/krss/CMakeLists.txt
+++ b/krss/CMakeLists.txt
@@ -41,11 +41,9 @@ set(krss_LIB_SRCS
feedlist.cpp
dbushelper.cpp
helper.cpp
- itemmodel.cpp
feeditemmodel.cpp
treenode.cpp
treenodevisitor.cpp
- feedlistmodel.cpp
exportopmljob.cpp
importitemsjob.cpp
importopmljob.cpp
@@ -55,7 +53,6 @@ set(krss_LIB_SRCS
itemjobs.cpp
statusmodifyjob.cpp
netfeedcreatejob.cpp
- standardactionmanager.cpp
#subscriptionsmodel.cpp
tagjobs.cpp
tagprovider.cpp
@@ -136,15 +133,12 @@ set(krss_LIB_HDRS
itemlisting.h
itemlistjob.h
feeditemmodel.h
- itemmodel.h
importitemsjob.h
importopmljob.h
- feedlistmodel.h
itemjobs.h
feedjobs.h
statusmodifyjob.h
netfeedcreatejob.h
- standardactionmanager.h
subscriptionsmodel.h
tagjobs.h
tagprovider.h
diff --git a/krss/feeditemmodel.cpp b/krss/feeditemmodel.cpp
index fe0eab7..6608134 100644
--- a/krss/feeditemmodel.cpp
+++ b/krss/feeditemmodel.cpp
@@ -105,13 +105,11 @@ QVariant FeedItemModel::entityData( const Akonadi::Item \
&akonadiItem, int column default:
break;
}
-#if 0
//PENDING(frank) TODO: use configurable colors
if ( role == Qt::ForegroundRole ) {
if ( RssItem::isUnread( akonadiItem ) )
return Qt::blue;
}
-#endif
if ( role == Qt::DecorationRole && column == ItemTitleColumn && \
RssItem::isImportant( akonadiItem ) ) return d->importantIcon;
diff --git a/krss/feedlistmodel.cpp b/krss/feedlistmodel.cpp
deleted file mode 100644
index 9ffcc42..0000000
--- a/krss/feedlistmodel.cpp
+++ /dev/null
@@ -1,696 +0,0 @@
-/*
- Copyright (C) 2008,2009 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "feedlistmodel.h"
-#include "tag.h"
-#include "tagprovider.h"
-#include "treenode.h"
-#include "treenodevisitor.h"
-#include "feedlist.h"
-#include "feedjobs.h"
-
-#include <KLocale>
-#include <KIcon>
-#include <KIconLoader>
-
-#include <QtCore/QPointer>
-#include <QtCore/QMimeData>
-#include <QtCore/QHashIterator>
-
-#include <QtGui/QPixmap>
-
-#include <cassert>
-
-using namespace KRss;
-using boost::shared_ptr;
-using boost::dynamic_pointer_cast;
-
-const char KRSS_TREENODE_MIMETYPE[] = "krss/treenode-id";
-
-namespace KRss {
-
-class FeedListModelPrivate
-{
-public:
- FeedListModelPrivate( const shared_ptr<const FeedList>& feedList,
- const shared_ptr<const TagProvider>& tagProvider,
- FeedListModel * const qq );
-
- shared_ptr<TagNode> addTagNode( const Tag& tag );
- void addFeed( const Feed::Id& feedId );
- void addFeedNode( const Feed::Id& feedId, const TagId& tagId );
- void removeFeedNode( const shared_ptr<FeedNode>& feedNode );
- QList<TagId> lookupTags( const Feed::Id& feedId ) const;
- shared_ptr<FeedNode> lookupFeedNode( const Feed::Id& feedId, const TagId &tagId \
) const;
- shared_ptr<TreeNode> lookupTreeNode( const TreeNode *treeNode ) const;
- QModelIndex createIndex( int row, int column, const boost::shared_ptr<TreeNode>& \
treeNode ) const;
-
- void slotTagCreated( const Tag& tag );
- void slotTagModified( const Tag& tag );
- void slotTagDeleted( const TagId& id );
- void slotFeedAdded( const Feed::Id& feedId );
- void slotFeedChanged( const Feed::Id& feedId );
- void slotFeedRemoved( const Feed::Id& feedId );
- void slotFeedItemCountChanged( const Feed::Id& feedId, int count );
- void reset();
-
-public:
- FeedListModel * const q;
-
- shared_ptr<const FeedList> m_feedList;
- const shared_ptr<const TagProvider> m_tagProvider;
- Tag m_allFeedsTag;
-
- shared_ptr<RootNode> m_rootNode;
- QHash<Feed::Id, QList<shared_ptr<FeedNode> > > m_feedNodes;
- QHash<TagId, shared_ptr<TagNode> > m_tagNodes;
-};
-
-} // namespace KRss
-
-namespace {
- class SignalBlocker
- {
- public:
- explicit SignalBlocker( QObject* o ) : object( o ), wasBlocked( \
o->blockSignals( true ) ) {}
- ~SignalBlocker() { if ( object ) object->blockSignals( wasBlocked ); }
- private:
- const QPointer<QObject> object;
- const bool wasBlocked;
- };
-
- class GetIconVisitor : public ConstTreeNodeVisitor
- {
- public:
- GetIconVisitor( const shared_ptr<const FeedList> feedList )
- : m_feedList( feedList ) {}
-
- void visit( const boost::shared_ptr<const RootNode>& ) {
- }
-
- void visit( const boost::shared_ptr<const TagNode>& tagNode ) {
- m_icon = KIcon( QLatin1String("folder") ).pixmap( KIconLoader::SizeSmall \
);
- }
-
- void visit( const boost::shared_ptr<const FeedNode>& feedNode ) {
- const boost::shared_ptr<const Feed> feed = m_feedList->constFeedById( \
feedNode->feedId() );
- if ( feed->isFetching() ) {
- m_icon = feed->icon().pixmap( KIconLoader::SizeSmall, QIcon::Active \
);
- } else {
- if ( !feed->hasError() )
- m_icon = feed->icon().pixmap( KIconLoader::SizeSmall, \
QIcon::Normal );
- else
- m_icon = KIcon( QLatin1String("dialog-warning") ).pixmap( \
KIconLoader::SizeSmall );
- }
- }
-
- const shared_ptr<const FeedList> m_feedList;
- QPixmap m_icon;
- };
-
- class ToolTipVisitor : public ConstTreeNodeVisitor
- {
- public:
- ToolTipVisitor( const shared_ptr<const FeedList> feedList )
- : m_feedList( feedList ) {}
-
- void visit( const boost::shared_ptr<const RootNode>& r ) {
- m_toolTip = r->title( m_feedList );
- }
-
- void visit( const boost::shared_ptr<const TagNode>& tagNode ) {
- m_toolTip = tagNode->title( m_feedList );
- }
-
- void visit( const boost::shared_ptr<const FeedNode>& feedNode ) {
- const boost::shared_ptr<const Feed> feed = m_feedList->constFeedById( \
feedNode->feedId() );
- if ( feed->isFetching() || !feed->hasError() )
- m_toolTip = feed->title();
- else
- m_toolTip = feed->errorString();
- }
-
- const shared_ptr<const FeedList> m_feedList;
- QString m_toolTip;
- };
-
- class CreateChildIndexVisitor : public TreeNodeVisitor
- {
- public:
- CreateChildIndexVisitor( const FeedListModelPrivate *model, int row, int \
column )
- : m_model( model ), m_row( row ), m_column( column ) {}
-
- QModelIndex childIndex() const { return m_childIndex; }
-
- void visit( const boost::shared_ptr<RootNode>& rootNode ) {
- Q_UNUSED( rootNode )
- Q_ASSERT_X( false, "CreateChildIndexVisitor::visit()", "Called for the \
root node" );
- }
-
- void visit( const boost::shared_ptr<TagNode>& tagNode ) {
- m_childIndex = ( m_row < tagNode->feedNodesCount() ?
- m_model->createIndex( m_row, m_column, \
tagNode->feedNodeAt( m_row ) ) : QModelIndex() );
- }
-
- void visit( const boost::shared_ptr<FeedNode>& feedNode ) {
- Q_UNUSED( feedNode )
- Q_ASSERT_X( false, "CreateChildIndexVisitor::visit()", "Called for the \
root node" );
- }
-
- private:
- const FeedListModelPrivate* const m_model;
- const int m_row;
- const int m_column;
- QModelIndex m_childIndex;
- };
-
- class CreateParentIndexVisitor : public TreeNodeVisitor
- {
- public:
- CreateParentIndexVisitor( const FeedListModelPrivate *model )
- : m_model( model ) {}
-
- QModelIndex parentIndex() const { return m_parentIndex; }
-
- void visit( const boost::shared_ptr<RootNode>& rootNode ) {
- Q_UNUSED( rootNode )
- Q_ASSERT_X( false, "CreateParentIndexVisitor::visit()", "Called for the \
root node" );
- }
-
- void visit( const boost::shared_ptr<TagNode>& tagNode ) {
- Q_UNUSED( tagNode )
- m_parentIndex = QModelIndex();
- }
-
- void visit( const boost::shared_ptr<FeedNode>& feedNode ) {
- const shared_ptr<TagNode> tagNode = feedNode->parent();
- m_parentIndex = m_model->createIndex( tagNode->row(), 0, tagNode );
- }
-
- private:
- const FeedListModelPrivate* const m_model;
- QModelIndex m_parentIndex;
- };
-}
-
-
-// private implementation
-FeedListModelPrivate::FeedListModelPrivate( const shared_ptr<const FeedList>& \
feedList,
- const shared_ptr<const TagProvider>& \
tagProvider,
- FeedListModel * const qq )
- : q( qq ), m_feedList( feedList ), m_tagProvider( tagProvider )
-{
- // construct the root node
- m_rootNode = shared_ptr<RootNode>( new RootNode );
-
- // construct the "All feeds" node
- m_allFeedsTag = Tag( TagId( "http://akregator.kde.org/defaultTags/AllFeeds" ) );
- m_allFeedsTag.setLabel( i18n( "All Feeds" ) );
- m_allFeedsTag.setDescription( i18n( "Contains all your feeds" ) );
- addTagNode( m_allFeedsTag );
-
- // walk over the TagProvider and construct tag nodes for all tags
- const QList<Tag> allTags = m_tagProvider->tags().values();
- Q_FOREACH( const Tag& tag, allTags ) {
- addTagNode( tag );
- }
-}
-
-shared_ptr<TagNode> FeedListModelPrivate::addTagNode( const Tag& tag )
-{
- const shared_ptr<TagNode> tagNode( new TagNode( m_rootNode ) );
- tagNode->setTag( tag );
-
- m_rootNode->appendTagNode( tagNode );
- m_tagNodes.insert( tag.id(), tagNode );
- return tagNode;
-}
-
-void FeedListModelPrivate::addFeed( const Feed::Id& feedId ) {
- const shared_ptr<const Feed> feed = m_feedList->constFeedById( feedId );
- const QList<TagId> feedTags = feed->tags() << m_allFeedsTag.id();
-
- Q_FOREACH( const TagId &tag, feedTags )
- addFeedNode( feedId, tag );
-}
-
-void FeedListModelPrivate::addFeedNode( const Feed::Id& feedId, const TagId& tagId )
-{
- if ( !m_tagNodes.contains( tagId ) )
- return;
-
- const shared_ptr<TagNode> tagNode = m_tagNodes.value( tagId );
-
- // create the feed node
- QModelIndex tagIndex = q->createIndex( tagNode->row(), 0, tagNode.get() );
- const int feedrow = tagNode->feedNodesCount();
- q->beginInsertRows( tagIndex, feedrow, feedrow );
- shared_ptr<FeedNode> feedNode( new FeedNode( tagNode ) );
- feedNode->setFeedId( feedId );
- tagNode->appendFeedNode( feedNode );
- m_feedNodes[ feedId ].append( feedNode );
- q->endInsertRows();
-}
-
-void FeedListModelPrivate::removeFeedNode( const shared_ptr<FeedNode>& feedNode )
-{
- const Feed::Id feedId = feedNode->feedId();
-
- // remove the feed node
- const shared_ptr<TagNode> tagNode = feedNode->parent();
- Q_ASSERT( tagNode );
-
- const int tagrow = tagNode->row();
- QModelIndex tagIndex = q->createIndex( tagrow, 0, tagNode.get() );
- const int feedrow = feedNode->row();
- q->beginRemoveRows( tagIndex, feedrow, feedrow );
- m_feedNodes[ feedId ].removeOne( feedNode );
- tagNode->removeFeedNodeAt( feedrow );
- q->endRemoveRows();
-}
-
-QList<TagId> FeedListModelPrivate::lookupTags( const Feed::Id& feedId ) const
-{
- const QList<shared_ptr<FeedNode> > feedNodes = m_feedNodes.value( feedId );
- QList<TagId> tags;
- Q_FOREACH( const shared_ptr<FeedNode>& feedNode, feedNodes ) {
- const shared_ptr<TagNode> tagNode = feedNode->parent();
- Q_ASSERT( tagNode );
- const Tag tag = tagNode->tag();
- tags.append( tag.id() );
- }
-
- return tags;
-}
-
-shared_ptr<FeedNode> FeedListModelPrivate::lookupFeedNode( const Feed::Id& feedId, \
const TagId& tagId ) const
-{
- const QList<shared_ptr<FeedNode> > feedNodes = m_feedNodes.value( feedId );
- Q_FOREACH( const shared_ptr<FeedNode>& feedNode, feedNodes ) {
- if ( feedNode->parent()->tag().id() == tagId )
- return feedNode;
- }
-
- Q_ASSERT_X( false, "FeedListModelPrivate::lookupFeedNode", "No such feed node" \
);
- return shared_ptr<FeedNode>();
-}
-
-shared_ptr<TreeNode> FeedListModelPrivate::lookupTreeNode( const TreeNode *treeNode \
) const
-{
- switch( treeNode->tier() ) {
- case TreeNode::RootTier:
- return m_rootNode;
- case TreeNode::TagTier:
- {
- const TagNode * const tagNodePtr = dynamic_cast<const TagNode*>( \
treeNode );
- Q_ASSERT( tagNodePtr );
- const shared_ptr<TreeNode> tagNode = m_tagNodes.value( \
tagNodePtr->tag().id() );
- Q_ASSERT( tagNode );
- return tagNode;
- }
- case TreeNode::FeedTier:
- {
- const FeedNode* const feedNodePtr = dynamic_cast<const FeedNode*>( \
treeNode );
- Q_ASSERT( feedNodePtr );
- const shared_ptr<TreeNode> feedNode = lookupFeedNode( \
feedNodePtr->feedId(),
- \
feedNodePtr->parent()->tag().id() );
- Q_ASSERT( feedNode );
- return feedNode;
- }
- default:
- Q_ASSERT_X( false, "FeedListModelPrivate::lookupTreeNode", "Unknown node \
tier" );
- }
-
- return shared_ptr<TreeNode>();
-}
-
-QModelIndex FeedListModelPrivate::createIndex( int row, int column, const \
shared_ptr<TreeNode>& treeNode ) const
-{
- return q->createIndex( row, column, treeNode.get() );
-}
-
-void FeedListModelPrivate::reset()
-{
- // we block signals and then call reset() to update
- // the model in one sitting
- if ( m_feedList ) {
- const SignalBlocker blocker( q );
- Q_FOREACH( const Feed::Id& feedId, m_feedList->feedIds() )
- addFeed( feedId );
- }
- q->reset();
-}
-
-void FeedListModelPrivate::slotTagCreated( const KRss::Tag& tag )
-{
- const shared_ptr<TagNode> tagNode = addTagNode( tag );
- const int row = tagNode->row();
- q->beginInsertRows( QModelIndex(), row, row );
- q->endInsertRows();
-}
-
-void FeedListModelPrivate::slotTagModified( const KRss::Tag& tag )
-{
- Q_ASSERT( m_tagNodes.contains( tag.id() ) );
-
- const shared_ptr<TagNode> tagNode = m_tagNodes.value( tag.id() );
- const QModelIndex tagIndex = q->createIndex( tagNode->row(), 0, tagNode.get() );
- tagNode->setTag( tag );
- emit q->dataChanged( tagIndex, tagIndex );
-}
-
-void FeedListModelPrivate::slotTagDeleted( const KRss::TagId& id )
-{
- Q_ASSERT( m_tagNodes.value( id )->feedNodesCount() == 0 );
-
- const shared_ptr<TagNode> tagNode = m_tagNodes.value( id );
- const int row = tagNode->row();
- q->beginRemoveRows( QModelIndex(), row, row );
- m_tagNodes.remove( id );
- m_rootNode->removeTagNodeAt( row );
- q->endRemoveRows();
-}
-
-void FeedListModelPrivate::slotFeedAdded( const Feed::Id& feedId )
-{
- addFeed( feedId );
-}
-
-void FeedListModelPrivate::slotFeedChanged( const Feed::Id& feedId )
-{
- const shared_ptr<const Feed> feed = m_feedList->feedById( feedId );
- const QList<TagId> newTags = feed->tags() << m_allFeedsTag.id();
-
- const QList<TagId> oldTags = lookupTags( feedId );
- const QSet<TagId> common = oldTags.toSet().intersect( newTags.toSet() );
- const QSet<TagId> toRemove = oldTags.toSet().subtract( newTags.toSet() );
- const QSet<TagId> toAdd = newTags.toSet().subtract( oldTags.toSet() );
-
- // updated the feed nodes under the 'common' tags
- Q_FOREACH( const TagId &tag, common ) {
- const shared_ptr<FeedNode> feedNode = lookupFeedNode( feedId, tag );
- const QModelIndex feedIndex = q->createIndex( feedNode->row(), 0, \
feedNode.get() );
- emit q->dataChanged( feedIndex, feedIndex );
- }
-
- // remove the feed nodes from the 'toRemove' tags
- Q_FOREACH( const TagId &tag, toRemove ) {
- const shared_ptr<FeedNode> feedNode = lookupFeedNode( feedId, tag );
- removeFeedNode( feedNode );
- }
-
- // add new feed nodes under the 'toAdd' tags
- Q_FOREACH( const TagId &tag, toAdd ) {
- addFeedNode( feedId, tag );
- }
-}
-
-void FeedListModelPrivate::slotFeedItemCountChanged( const Feed::Id& feedId, int ) {
- //TODO: make this more efficient
- slotFeedChanged( feedId );
-}
-
-void FeedListModelPrivate::slotFeedRemoved( const Feed::Id& feedId )
-{
- const QList<shared_ptr<FeedNode> > feedNodes = m_feedNodes.value( feedId );
- Q_FOREACH( const shared_ptr<FeedNode> feedNode, feedNodes ) {
- removeFeedNode( feedNode );
- }
-}
-
-// public interface implementation
-FeedListModel::FeedListModel( const shared_ptr<const FeedList>& feedList,
- const shared_ptr<const TagProvider>& tagProvider,
- QObject *parent )
- : QAbstractItemModel( parent ), d( new FeedListModelPrivate( feedList, \
tagProvider, this ) )
-{
- if ( d->m_feedList ) {
- connect( d->m_feedList.get(), SIGNAL(feedAdded(KRss::Feed::Id)),
- this, SLOT(slotFeedAdded(KRss::Feed::Id)) );
- connect( d->m_feedList.get(), SIGNAL(feedChanged( KRss::Feed::Id)),
- this, SLOT(slotFeedChanged(KRss::Feed::Id)) );
- connect( d->m_feedList.get(), SIGNAL(feedRemoved(KRss::Feed::Id)),
- this, SLOT(slotFeedRemoved(KRss::Feed::Id)) );
- connect( d->m_feedList.get(), \
SIGNAL(unreadCountChanged(KRss::Feed::Id,int)),
- this, SLOT(slotFeedItemCountChanged(KRss::Feed::Id,int)) );
- connect( d->m_feedList.get(), SIGNAL(totalCountChanged(KRss::Feed::Id,int)),
- this, SLOT(slotFeedItemCountChanged(KRss::Feed::Id,int)) );
-
- Q_FOREACH( const Feed::Id& feedId, d->m_feedList->feedIds() )
- d->addFeed( feedId );
- }
-
- connect( d->m_tagProvider.get(), SIGNAL(tagCreated(KRss::Tag)),
- this, SLOT(slotTagCreated(KRss::Tag)) );
- connect( d->m_tagProvider.get(), SIGNAL(tagModified(KRss::Tag)),
- this, SLOT(slotTagModified(KRss::Tag)) );
- connect( d->m_tagProvider.get(), SIGNAL(tagDeleted(KRss::TagId)),
- this, SLOT(slotTagDeleted(KRss::TagId)) );
-}
-
-FeedListModel::~FeedListModel()
-{
- delete d;
-}
-
-shared_ptr<const FeedList> FeedListModel::feedList() const
-{
- return d->m_feedList;
-}
-
-QVariant FeedListModel::headerData( int section, Qt::Orientation orientation, int \
role ) const
-{
- if ( orientation != Qt::Horizontal || role != Qt::DisplayRole )
- return QVariant();
-
- switch ( section ) {
- case TitleColumn: return i18n( "Feeds" );
- case UnreadCountColumn: return i18n( "Unread" );
- case TotalCountColumn: return i18n( "Total" );
- default:
- break;
- }
-
- return QVariant();
-}
-
-int FeedListModel::columnCount( const QModelIndex &parent ) const
-{
- Q_UNUSED( parent );
- return ColumnCount;
-}
-
-int FeedListModel::rowCount( const QModelIndex &parent ) const
-{
- if ( !parent.isValid() )
- return d->m_rootNode->tagNodesCount();
-
- const TreeNode* const node = static_cast<const TreeNode*>( \
parent.internalPointer() );
- const shared_ptr<const TreeNode> treeNode = d->lookupTreeNode( node );
- return treeNode->childCount();
-}
-
-QVariant FeedListModel::data(const QModelIndex &index, int role ) const
-{
- if ( !index.isValid() )
- return QVariant();
-
- const TreeNode* const node = static_cast<const TreeNode*>( \
index.internalPointer() );
- const shared_ptr<TreeNode> treeNode = d->lookupTreeNode( node );
-
- switch ( role ) {
- case Qt::EditRole:
- case Qt::DisplayRole:
- {
- switch ( index.column() )
- {
- case TitleColumn:
- return treeNode->title( d->m_feedList );
- case UnreadCountColumn:
- return treeNode->unreadCount( d->m_feedList );
- case TotalCountColumn:
- return treeNode->totalCount( d->m_feedList );
- }
- break;
- }
- case Qt::DecorationRole:
- {
- if ( index.column() != TitleColumn )
- return QVariant();
-
- GetIconVisitor visitor( d->m_feedList );
- treeNode->accept( &visitor );
- return visitor.m_icon;
- }
- case Qt::ToolTipRole:
- {
- if ( index.column() != TitleColumn )
- return QVariant();
-
- ToolTipVisitor visitor( d->m_feedList );
- treeNode->accept( &visitor );
- return visitor.m_toolTip;
- }
- case HasUnreadRole: return treeNode->unreadCount( d->m_feedList ) > 0;
- case TreeNodeRole: return QVariant::fromValue( treeNode );
- case IsTagRole: return treeNode->tier() == TreeNode::TagTier;
-
- default: return QVariant();
- }
-
- return QVariant();
-}
-
-QModelIndex FeedListModel::index( int row, int column, const QModelIndex &parent ) \
const
-{
- if ( row < 0 || column < 0 || column > ColumnCount )
- return QModelIndex();
-
- // create index for a tag node
- if ( !parent.isValid() ) {
- if ( row < d->m_rootNode->tagNodesCount() )
- return createIndex( row, column, d->m_rootNode->tagNodeAt( row ).get() \
);
- else
- return QModelIndex();
- }
-
- // node is a Tag node, CreateChildIndexVisitor checks this
- const TreeNode* const node = static_cast<const TreeNode*>( \
parent.internalPointer() );
- const shared_ptr<TreeNode> treeNode = d->lookupTreeNode( node );
- CreateChildIndexVisitor visitor( d, row, column );
- treeNode->accept( &visitor );
- return visitor.childIndex();
-}
-
-QModelIndex FeedListModel::parent( const QModelIndex &index ) const
-{
- if ( !index.isValid() )
- return QModelIndex();
-
- // node is either a Tag node or Feed node, CreateParentIndexVisitor checks this
- const TreeNode* const node = static_cast<const TreeNode*>( \
index.internalPointer() );
- const shared_ptr<TreeNode> treeNode = d->lookupTreeNode( node );
- CreateParentIndexVisitor visitor( d );
- treeNode->accept( &visitor );
- return visitor.parentIndex();
-}
-
-Qt::ItemFlags FeedListModel::flags( const QModelIndex& index ) const
-{
- const Qt::ItemFlags flags = QAbstractItemModel::flags( index );
- if ( !index.isValid() || ( index.column() != TitleColumn ) )
- return flags;
-
- const shared_ptr<const TreeNode> treeNode = FeedListModel::data( index, \
FeedListModel::TreeNodeRole )
- \
.value<shared_ptr<TreeNode> >();
- if ( treeNode->tier() == TreeNode::TagTier )
- return flags | Qt::ItemIsDropEnabled;
- else
- return flags | Qt::ItemIsDragEnabled;
-}
-
-QStringList FeedListModel::mimeTypes() const
-{
- QStringList types;
- types << QLatin1String("text/uri-list") << \
QLatin1String(KRSS_TREENODE_MIMETYPE);
- return types;
-}
-
-QMimeData* FeedListModel::mimeData( const QModelIndexList& indexes ) const
-{
- QMimeData* mimeData = new QMimeData;
- QList<QUrl> urls;
- QByteArray idList;
- QDataStream idStream( &idList, QIODevice::WriteOnly );
-
- Q_FOREACH ( const QModelIndex& index, indexes ) {
- const shared_ptr<const TreeNode> treeNode = FeedListModel::data( index, \
FeedListModel::TreeNodeRole )
- \
.value<shared_ptr<TreeNode> >();
- switch( treeNode->tier() ) {
- case TreeNode::FeedTier:
- {
- const shared_ptr<const FeedNode> feedNode = \
dynamic_pointer_cast<const FeedNode, const TreeNode>( treeNode );
- // TODO: figure out how to handle virtual search feeds
- //urls.append( d->m_feedList->constFeedById( feedNode->feedId() \
)->xmlUrl() );
- idStream << feedNode->feedId();
- break;
- }
- default:
- Q_ASSERT_X( false, "FeedListModel::mimeData()", "Default path \
reached" );
- }
- }
-
- mimeData->setUrls( urls );
- mimeData->setData( QLatin1String(KRSS_TREENODE_MIMETYPE), idList );
- return mimeData;
-}
-
-bool FeedListModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int \
row, int column,
- const QModelIndex& parent )
-{
- // TODO: support rearranging order of the tags and feeds
- Q_UNUSED( column )
- Q_UNUSED( row )
-
- if ( action == Qt::IgnoreAction )
- return true;
-
- if ( !data->hasFormat( QLatin1String(KRSS_TREENODE_MIMETYPE) ) )
- return false;
-
- const shared_ptr<const TreeNode> droppedOnNode = FeedListModel::data( parent, \
FeedListModel::TreeNodeRole )
- \
.value<shared_ptr<TreeNode> >();
- if ( !droppedOnNode )
- return false;
-
- if ( droppedOnNode->tier() != TreeNode::TagTier )
- return false;
-
- const shared_ptr<const TagNode> droppedOnTag = dynamic_pointer_cast<const \
TagNode, const TreeNode>( droppedOnNode );
- assert( droppedOnTag );
- if ( droppedOnTag->tag() == d->m_allFeedsTag )
- return false;
-
- QByteArray idData = data->data( QLatin1String(KRSS_TREENODE_MIMETYPE) );
- QDataStream stream( idData );
- while ( !stream.atEnd() ) {
- KRss::Feed::Id id;
- stream >> id;
- const shared_ptr<Feed> feed = d->m_feedList->feedById( id );
- Q_ASSERT( feed );
- feed->addTag( droppedOnTag->tag().id() );
- // TODO: figure out how to pass the error message up to the main window
- FeedModifyJob * const job = new FeedModifyJob( feed );
- job->start();
- }
-
- return true;
-}
-
-QList<QModelIndex> FeedListModel::feedIndexes( const Feed::Id& feedId ) const
-{
- QList<QModelIndex> feedIndexesList;
-
- QList<shared_ptr<FeedNode> > feedNodes = d->m_feedNodes.value( feedId );
- Q_FOREACH( const shared_ptr<FeedNode> feedNode, feedNodes ) {
- feedIndexesList.append( createIndex ( feedNode->row(), 0, feedNode.get() ) \
);
- }
-
- return feedIndexesList;
-}
-
-#include "feedlistmodel.moc"
diff --git a/krss/feedlistmodel.h b/krss/feedlistmodel.h
deleted file mode 100644
index a51632f..0000000
--- a/krss/feedlistmodel.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- Copyright (C) 2008 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef KRSS_FEEDLISTMODEL_H
-#define KRSS_FEEDLISTMODEL_H
-
-#include "krss_export.h"
-#include "feed.h"
-
-#include <QtCore/QAbstractItemModel>
-
-#include <boost/shared_ptr.hpp>
-
-namespace KRss {
-
-class Feed;
-class FeedList;
-class TagProvider;
-
-class KRSS_EXPORT FeedListModel : public QAbstractItemModel
-{
- Q_OBJECT
-
-public:
- enum Role {
- TreeNodeRole = Qt::UserRole,
- HasUnreadRole,
- IsTagRole,
- UserRole = HasUnreadRole+100
- };
-
- enum Column {
- TitleColumn=0,
- UnreadCountColumn,
- TotalCountColumn,
- ColumnCount
- };
-public:
-
- FeedListModel( const boost::shared_ptr<const FeedList>& feedlist,
- const boost::shared_ptr<const TagProvider>& tagProvider,
- QObject *parent = 0 );
- ~FeedListModel();
-
- boost::shared_ptr<const FeedList> feedList() const;
-
- QVariant headerData( int section, Qt::Orientation orientation, int role = \
Qt::DisplayRole ) const;
- int columnCount( const QModelIndex &parent = QModelIndex() ) const;
- int rowCount( const QModelIndex &parent = QModelIndex() ) const;
- QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
- QModelIndex index( int row, int column, const QModelIndex &parent = \
QModelIndex() ) const;
- QModelIndex parent( const QModelIndex &index ) const;
- Qt::ItemFlags flags( const QModelIndex& index ) const;
- QStringList mimeTypes() const;
- QMimeData* mimeData( const QModelIndexList& indexes ) const;
- bool dropMimeData( const QMimeData* data, Qt::DropAction action, int row, int \
column, const QModelIndex& parent );
-
-protected:
-
- // helper methods
- QList<QModelIndex> feedIndexes( const Feed::Id& id ) const;
-
-private:
-
- friend class FeedListModelPrivate;
- class FeedListModelPrivate * const d;
-
- Q_DISABLE_COPY( FeedListModel )
- Q_PRIVATE_SLOT( d, void slotTagCreated( const KRss::Tag& tag ) )
- Q_PRIVATE_SLOT( d, void slotTagModified( const KRss::Tag& tag ) )
- Q_PRIVATE_SLOT( d, void slotTagDeleted( const KRss::TagId& id ) )
- Q_PRIVATE_SLOT( d, void slotFeedAdded( const KRss::Feed::Id& id ) )
- Q_PRIVATE_SLOT( d, void slotFeedChanged( const KRss::Feed::Id& id ) )
- Q_PRIVATE_SLOT( d, void slotFeedRemoved( const KRss::Feed::Id& id) )
- Q_PRIVATE_SLOT( d, void slotFeedItemCountChanged( const KRss::Feed::Id& id, int \
count ) )
-};
-
-} // namespace KRss
-
-#endif // KRSS_FEEDLISTMODEL_H
diff --git a/krss/itemmodel.cpp b/krss/itemmodel.cpp
deleted file mode 100644
index 26d786f..0000000
--- a/krss/itemmodel.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- Copyright (C) 2008 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "itemmodel.h"
-#include "feed.h"
-#include "person.h"
-#include "itemlisting.h"
-#include "itemlistjob.h"
-
-#include <akonadi/itemfetchscope.h>
-
-#include <KIcon>
-#include <KGlobal>
-#include <KLocale>
-#include <KDateTime>
-#include <KDebug>
-
-#include <QtCore/QTimer>
-
-#include <cassert>
-
-using namespace boost;
-using namespace KRss;
-
-class KRss::ItemModelPrivate : public ItemListing::Listener {
- ItemModel* const q;
-
-public:
- explicit ItemModelPrivate( const shared_ptr<ItemListing>& coll, ItemModel* qq );
- ~ItemModelPrivate();
-
- void prepareInsert( int idx ) {
- q->beginInsertRows( QModelIndex(), idx, idx );
- }
-
- void finishInsert( int ) {
- q->endInsertRows();
- }
-
- void prepareRemove( int idx ) {
- q->beginRemoveRows( QModelIndex(), idx, idx );
- }
-
- void finishRemove( int ) {
- q->endRemoveRows();
- }
-
- void update( int idx ) {
- emit q->dataChanged( q->index( idx, ItemModel::ItemTitleColumn ), q->index( \
idx, ItemModel::ColumnCount - 1 ) );
- }
-
- const shared_ptr<ItemListing> items;
- KIcon m_importantIcon;
-};
-
-ItemModelPrivate::ItemModelPrivate( const shared_ptr<ItemListing>& items_, \
ItemModel* qq )
- : q( qq ), items( items_ ), m_importantIcon( KIcon( \
QLatin1String("mail-mark-important") ) )
-{
- items->addListener( this );
-}
-
-ItemModelPrivate::~ItemModelPrivate() {
- items->removeListener( this );
-}
-
-
-ItemModel::ItemModel( const shared_ptr<ItemListing>& coll, QObject *parent )
- : QAbstractTableModel( parent ), d( new ItemModelPrivate( coll, this ) )
-{
-}
-
-ItemModel::~ItemModel()
-{
- delete d;
-}
-
-Item ItemModel::itemForIndex( const QModelIndex &index ) const
-{
- const int row = index.row();
- if ( row < 0 || row >= d->items->items().count() )
- return Item();
-
- return d->items->items().at( row );
-}
-
-int ItemModel::columnCount( const QModelIndex &parent ) const
-{
- return ( !parent.isValid() ? 4 : 0 );
-}
-
-QVariant ItemModel::data( const QModelIndex &index, int role ) const
-{
- if ( !index.isValid() ) {
- return QVariant();
- }
-
- const int row = index.row();
-
- if ( row < 0 || row >= d->items->items().count() ) {
- return QVariant();
- }
-
- const Item& item = d->items->items()[row];
-
- if ( role == SortRole && index.column() == DateColumn )
- return item.dateUpdated().toTime_t();
-
- if ( role == IsDeletedRole )
- return false;
-
- if ( role == Qt::DisplayRole || role == SortRole ) {
- QString authors;
- switch ( index.column() ) {
- case ItemTitleColumn:
- return item.titleAsPlainText();
- case AuthorsColumn:
- Q_FOREACH( const KRss::Person &person, item.authors() ) {
- authors += person.name() + QLatin1Char(';');
- }
- authors.remove( authors.length() - 1, 1 );
- return authors;
- case DateColumn:
- return KGlobal::locale()->formatDateTime( item.dateUpdated(),
- KLocale::FancyShortDate );
- case FeedTitleColumn:
-#ifdef TEMPORARILY_REMOVED
- return d->m_feed->title();
-#endif
- default:
- return QVariant();
- }
- }
-
- if ( role == ItemRole ) {
- QVariant var;
- var.setValue( item );
- return var;
- }
-
- if ( role == ItemStatusRole ) {
- QVariant var;
- var.setValue( item.status() );
- return var;
- }
-
- if ( role == IsImportantRole )
- return item.isImportant();
-
- if ( role == IsUnreadRole )
- return item.isUnread();
-
- if ( role == IsReadRole )
- return item.isRead();
-
- if ( role == IsDeletedRole )
- return item.isDeleted();
-
- if ( role == LinkRole )
- return item.link();
-
- //PENDING(frank) TODO: use configurable colors
- if ( role == Qt::ForegroundRole ) {
- if ( item.isUnread() )
- return Qt::blue;
- }
-
- if ( role == Qt::DecorationRole && index.column() == ItemTitleColumn )
- return item.isImportant() ? d->m_importantIcon : QVariant();
-
- return QVariant();
-}
-
-int ItemModel::rowCount( const QModelIndex &parent ) const
-{
- return ( !parent.isValid() ? d->items->items().count() : 0 );
-}
-
-QVariant ItemModel::headerData( int section, Qt::Orientation orientation, int role ) \
const
-{
- if ( orientation != Qt::Horizontal || role != Qt::DisplayRole ) {
- return QVariant();
- }
-
- switch ( section ) {
- case ItemTitleColumn:
- return i18n( "Title" );
- case AuthorsColumn:
- return i18n( "Authors" );
- case DateColumn:
- return i18n( "Date" );
- case FeedTitleColumn:
- return i18n( "Feed" );
- default:
- return QVariant();
- }
-
- return QVariant();
-}
-
-#include "itemmodel.moc"
diff --git a/krss/itemmodel.h b/krss/itemmodel.h
deleted file mode 100644
index 678bade..0000000
--- a/krss/itemmodel.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- Copyright (C) 2008 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef KRSS_ITEMMODEL_H
-#define KRSS_ITEMMODEL_H
-
-#include "krss_export.h"
-#include "item.h"
-
-#include <QtCore/QAbstractTableModel>
-#include <QtCore/QMetaType>
-
-#include <boost/shared_ptr.hpp>
-
-class KJob;
-
-namespace KRss {
-
-class ItemListing;
-
-class ItemModelPrivate;
-
-class KRSS_EXPORT ItemModel : public QAbstractTableModel
-{
- Q_OBJECT
-
-public:
-
- enum Column {
- ItemTitleColumn = 0,
- AuthorsColumn,
- DateColumn,
- FeedTitleColumn,
- ColumnCount
- };
-
- enum Role {
- ItemRole = Qt::UserRole,
- ItemStatusRole,
- SortRole,
- IsUnreadRole,
- IsReadRole,
- IsDeletedRole, //PENDING(frank) transitional Akregator compat, review
- IsImportantRole, //PENDING(frank) transitional Akregator compat, review
- LinkRole //PENDING(frank) transitional Akregator compat, review
- };
-
-public:
-
- explicit ItemModel( const boost::shared_ptr<ItemListing>& itemCollection, \
QObject *parent = 0 );
- ~ItemModel();
-
- int columnCount( const QModelIndex &parent = QModelIndex() ) const;
- QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
- int rowCount( const QModelIndex &parent = QModelIndex() ) const;
- QVariant headerData( int section, Qt::Orientation orientation, int role = \
Qt::DisplayRole ) const;
-
-protected:
-
- Item itemForIndex( const QModelIndex &index ) const;
-
-private:
-
- Q_DISABLE_COPY(ItemModel)
- friend class ::KRss::ItemModelPrivate;
- ItemModelPrivate * const d;
-};
-
-} // namespace KRss
-
-Q_DECLARE_METATYPE(KRss::Item)
-
-#endif // KRSS_ITEMMODEL_H
diff --git a/krss/standardactionmanager.cpp b/krss/standardactionmanager.cpp
deleted file mode 100644
index 9d5bb74..0000000
--- a/krss/standardactionmanager.cpp
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- Copyright (C) 2008 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "standardactionmanager.h"
-#include "feedlist.h"
-#include "feedlistmodel.h"
-#include "treenode.h"
-#include "itemmodel.h"
-#include "feed.h"
-#include "item.h"
-#include "netfeed.h"
-#include "netfeedcreatejob.h"
-#include "feedjobs.h"
-#include "itemjobs.h"
-#include "resourcemanager.h"
-#include "netresource.h"
-#include "ui/netfeedcreatedialog.h"
-#include "ui/feedpropertiesdialog.h"
-#include "tagprovider.h"
-#include "tagjobs.h"
-#include "ui/tagpropertiesdialog.h"
-
-#include <KAction>
-#include <KActionCollection>
-#include <KDebug>
-#include <KLocale>
-#include <KInputDialog>
-#include <KMessageBox>
-
-#include <QtGui/QItemSelectionModel>
-#include <QtGui/QTreeView>
-
-#include <boost/static_assert.hpp>
-
-using namespace KRss;
-using boost::shared_ptr;
-using boost::dynamic_pointer_cast;
-
-static const struct {
- const char *name;
- const char *label;
- const char *icon;
- int shortcut;
- const char* slot;
-} actionData[] = {
- { "krss_feed_create", I18N_NOOP( "&New Feed..." ), "feed-subscribe", 0, SLOT( \
slotCreateNetFeed() ) },
- { "krss_feed_fetch", I18N_NOOP( "&Fetch Feed" ), "view-refresh", Qt::Key_F5, \
SLOT( slotFetchFeed() ) },
- { "krss_feed_abortfetch", I18N_NOOP( "&Abort Fetch" ), "process-stop", \
Qt::Key_F8, SLOT( slotAbortFetch() ) },
- { "krss_feed_properties", I18N_NOOP( "Feed &Properties..." ), \
"document-properties", 0, SLOT( slotFeedProperties() ) },
- { "krss_feed_delete", I18N_NOOP( "&Delete Feed" ), "edit-delete", 0, SLOT( \
slotDeleteFeed() ) },
- { "krss_tag_create", I18N_NOOP( "&Create tag" ), 0, 0, SLOT( slotCreateTag() ) \
},
- { "krss_tag_modify", I18N_NOOP( "&Modify tag" ), 0, 0, SLOT( slotModifyTag() ) \
},
- { "krss_tag_delete", I18N_NOOP( "&Delete tag" ), 0, 0, SLOT( slotDeleteTag() ) \
},
- { "krss_manage_subscriptions", I18N_NOOP( "&Manage subscriptions" ), 0, 0, SLOT( \
slotManageSubscriptions() ) },
- { "krss_item_mark_new", I18N_NOOP( "&Mark as new" ), "mail-mark-unread-new", 0, \
SLOT( slotMarkItemNew() ) },
- { "krss_item_mark_read", I18N_NOOP( "&Mark as read" ), "mail-mark-read", 0, \
SLOT( slotMarkItemRead() ) },
- { "krss_item_mark_unread", I18N_NOOP( "&Mark as unread" ), "mail-mark-unread", \
0, SLOT( slotMarkItemUnread() ) },
- { "krss_item_mark_important", I18N_NOOP( "&Mark as important" ), \
"mail-mark-important", 0, SLOT( slotMarkItemImportant( bool ) ) },
- { "krss_item_delete", I18N_NOOP( "&Delete item" ), "edit-delete", 0, SLOT( \
slotDeleteItem() ) }
-};
-static const int numActionData = sizeof (actionData) / sizeof (*actionData);
-
-BOOST_STATIC_ASSERT( numActionData == StandardActionManager::LastType );
-
-
-namespace KRss {
-
-class StandardActionManagerPrivate
-{
-public:
-
- StandardActionManagerPrivate( KActionCollection *actionCollection, QWidget \
*parent )
- : m_actionCollection( actionCollection ), m_parentWidget( parent ), \
m_feedSelectionModel( 0 ),
- m_itemSelectionModel( 0 )
- {
- }
-
- KActionCollection *m_actionCollection;
- QWidget *m_parentWidget;
- QItemSelectionModel *m_feedSelectionModel;
- QItemSelectionModel *m_itemSelectionModel;
- shared_ptr<const FeedList> m_feedList;
- QString m_subscriptionLabel;
- shared_ptr<const TagProvider> m_tagProvider;
- QVector<KAction*> m_actions;
-};
-
-} // namespace KRss
-
-
-StandardActionManager::StandardActionManager( KActionCollection *actionCollection, \
QWidget *parent )
- : d( new StandardActionManagerPrivate( actionCollection, parent ) )
-{
- d->m_actions.fill( 0, LastType );
-}
-
-StandardActionManager::~StandardActionManager()
-{
- delete d;
-}
-
-void StandardActionManager::setFeedSelectionModel( QItemSelectionModel \
*feedSelectionModel )
-{
- if ( d->m_feedSelectionModel )
- d->m_feedSelectionModel->disconnect( this );
-
- d->m_feedSelectionModel = feedSelectionModel;
- connect( d->m_feedSelectionModel, SIGNAL( selectionChanged( const \
QItemSelection&, const QItemSelection& ) ),
- this, SLOT( updateActions() ) );
-
- const FeedListModel * const model = qobject_cast<const FeedListModel*>( \
d->m_feedSelectionModel->model() );
- Q_ASSERT( model );
- d->m_feedList = model->feedList();
-}
-
-void StandardActionManager::setItemSelectionModel( QItemSelectionModel \
*itemSelectionModel )
-{
- if ( d->m_itemSelectionModel )
- d->m_itemSelectionModel->disconnect( this );
-
- d->m_itemSelectionModel = itemSelectionModel;
- connect( d->m_itemSelectionModel, SIGNAL( selectionChanged( const \
QItemSelection&, const QItemSelection& ) ),
- this, SLOT( updateActions() ) );
-}
-
-void StandardActionManager::setSubscriptionLabel( const QString &subscriptionLabel )
-{
- d->m_subscriptionLabel = subscriptionLabel;
-}
-
-void StandardActionManager::setTagProvider( const shared_ptr<const TagProvider>& \
provider )
-{
- Q_ASSERT( provider );
- d->m_tagProvider = provider;
- updateActions();
-}
-
-KAction* StandardActionManager::action( Type type )
-{
- Q_ASSERT( type >= 0 && type < LastType );
- Q_ASSERT( actionData[ type ].name );
-
- if ( d->m_actions[ type ] )
- return d->m_actions[ type ];
-
- KAction *action = new KAction( d->m_parentWidget );
- if ( actionData[ type ].label )
- action->setText( i18n( actionData[ type ].label ) );
-
- if ( actionData[ type ].icon )
- action->setIcon( KIcon( QString::fromLatin1( actionData[ type ].icon ) ) );
-
- action->setShortcut( actionData[ type ].shortcut );
-
- if ( actionData[ type ].slot )
- connect( action, SIGNAL( triggered( bool ) ), this, actionData[ type ].slot \
);
-
- if ( type == MarkItemImportant )
- action->setCheckable( true );
-
- d->m_actionCollection->addAction( QString::fromLatin1( actionData[ type ].name \
), action );
- d->m_actions[ type ] = action;
- updateActions();
- return action;
-}
-
-void StandardActionManager::createAllActions()
-{
- for ( int i = 0; i < LastType; ++i )
- action( (Type)i );
-}
-
-void StandardActionManager::enableAction( Type type, bool enable )
-{
- Q_ASSERT( type >= 0 && type < LastType );
- if ( d->m_actions[ type ] )
- d->m_actions[ type ]->setEnabled( enable );
-}
-
-void StandardActionManager::updateActions()
-{
- enableAction( StandardActionManager::ManageSubscriptions, true );
-
- // update actions for feeds
- // FIXME: only single selections, better to query the type of the node
- // FIXME: supports only persistent feeds
- enableAction( CreateNetFeed, true );
- bool enableFeedActions = false;
- const QModelIndexList selectedFeeds = d->m_feedSelectionModel ?
- d->m_feedSelectionModel->selectedRows() : \
QModelIndexList();
- if ( !selectedFeeds.isEmpty() ) {
- const shared_ptr<TreeNode> treeNode = selectedFeeds.first().data( \
FeedListModel::TreeNodeRole).
- value<shared_ptr<TreeNode> >();
- if ( treeNode->tier() == TreeNode::FeedTier )
- enableFeedActions = true;
- }
- enableAction( FetchFeed, enableFeedActions );
- enableAction( AbortFetch, enableFeedActions );
- enableAction( FeedProperties, enableFeedActions );
- enableAction( DeleteFeed, enableFeedActions );
-
- const QModelIndexList selectedItems = d->m_itemSelectionModel ? \
d->m_itemSelectionModel->selectedRows() : QModelIndexList();
-
- // update actions for items
- if ( !selectedItems.isEmpty() ) {
- // if there are multiple items selected, enable the MarkItemImportant
- // action only if all the items have the same state of the 'Important' flag
- bool enableImportant = true;
- const bool firstValue = selectedItems.first().data( \
ItemModel::ItemStatusRole ).value<KRss::Item::Status>() &
- KRss::Item::Important;
- Q_FOREACH( const QModelIndex &selectedIndex, selectedItems ) {
- if ( firstValue != ( selectedIndex.data( ItemModel::ItemStatusRole \
).value<KRss::Item::Status>() &
- KRss::Item::Important ) ) {
- enableImportant = false;
- break;
- }
- }
- enableAction( MarkItemNew, true );
- enableAction( MarkItemRead, true );
- enableAction( MarkItemUnread, true );
- enableAction( MarkItemImportant, enableImportant );
- action( MarkItemImportant )->setChecked( enableImportant ? firstValue : \
false );
- enableAction( DeleteItem, true );
- }
- else {
- enableAction( MarkItemNew, false );
- enableAction( MarkItemRead, false );
- enableAction( MarkItemUnread, false );
- enableAction( MarkItemImportant, false );
- action( MarkItemImportant )->setChecked( false );
- enableAction( DeleteItem, false );
- }
-
- // update tag-related actions
- if ( !selectedFeeds.isEmpty() ) {
- shared_ptr<TreeNode> treeNode = selectedFeeds.first().data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- if ( treeNode->tier() == TreeNode::TagTier ) {
- enableAction( CreateTag, true );
- enableAction( ModifyTag, true );
- enableAction( DeleteTag, true );
- }
- }
- else {
- enableAction( CreateTag, true );
- enableAction( ModifyTag, false );
- enableAction( DeleteTag, false );
- }
-}
-
-void StandardActionManager::slotCreateNetFeed()
-{
- NetFeedCreateDialog *dialog = new NetFeedCreateDialog( d->m_parentWidget );
-
- QList<QPair<QString, QString> > resourceDescriptions;
- const QList<shared_ptr<NetResource> > resources = \
ResourceManager::self()->netResources();
- Q_FOREACH( const shared_ptr<NetResource>& resource, resources ) {
- resourceDescriptions.append( QPair<QString, QString>( resource->id(), \
resource->name() ) );
- }
-
- dialog->setResourceDescriptions( resourceDescriptions );
- if ( dialog->exec() == KDialog::Accepted ) {
- const QString identifier = dialog->resourceIdentifier();
- const QString url = dialog->url();
-
- Q_FOREACH( const shared_ptr<NetResource>& resource, resources ) {
- if ( resource->id() == identifier ) {
- NetFeedCreateJob* const job = resource->netFeedCreateJob( url );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( \
slotNetFeedCreated( KJob* ) ) );
- job->start();
- break;
- }
- }
- }
-
- delete dialog;
-}
-
-void StandardActionManager::slotFetchFeed()
-{
- // FIXME: only single selections
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- if ( !selectedIndex.isValid() )
- return;
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<FeedNode> feedNode = boost::dynamic_pointer_cast<FeedNode, \
TreeNode>( treeNode );
- if ( !feedNode )
- return;
-
- d->m_feedList->constFeedById( feedNode->feedId() )->fetch();
-}
-
-void StandardActionManager::slotAbortFetch()
-{
- // FIXME: only single selections
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- if ( !selectedIndex.isValid() )
- return;
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<FeedNode> feedNode = boost::dynamic_pointer_cast<FeedNode, \
TreeNode>( treeNode );
- if ( !feedNode )
- return;
-
- d->m_feedList->constFeedById( feedNode->feedId() )->abortFetch();
-}
-
-void StandardActionManager::slotFeedProperties()
-{
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- if ( !selectedIndex.isValid() )
- return;
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<FeedNode> feedNode = boost::dynamic_pointer_cast<FeedNode, \
TreeNode>( treeNode );
- if ( !feedNode )
- return;
-
- shared_ptr<NetFeed> feed = dynamic_pointer_cast<NetFeed, Feed>( \
d->m_feedList->feedById( feedNode->feedId() ) );
-
- FeedPropertiesDialog *dialog = new FeedPropertiesDialog();
- dialog->setFeedTitle( feed->title() );
- dialog->setUrl( feed->xmlUrl() );
- dialog->setCustomFetchInterval( true ); // currently we don't use default \
settings
- dialog->setFetchInterval( feed->fetchInterval() );
-
- if ( dialog->exec() == KDialog::Accepted ) {
- feed->setTitle( dialog->feedTitle() );
- feed->setXmlUrl( dialog->url() );
- dialog->hasCustomFetchInterval() ? feed->setFetchInterval( \
dialog->fetchInterval() ) :
- feed->setFetchInterval( 0 );
-
- FeedModifyJob * const job = new FeedModifyJob( feed, this );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFeedModified( KJob* \
) ) );
- job->start();
- }
-
- delete dialog;
-}
-
-void StandardActionManager::slotDeleteFeed()
-{
- // FIXME: only single selections
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- if ( !selectedIndex.isValid() )
- return;
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<FeedNode> feedNode = boost::dynamic_pointer_cast<FeedNode, \
TreeNode>( treeNode );
- if ( !feedNode )
- return;
-
- shared_ptr<const Feed> feed = d->m_feedList->constFeedById( feedNode->feedId() \
);
- Q_ASSERT( feed );
-
- FeedDeleteJob * const job = new FeedDeleteJob( feed , this );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFeedDeleted( KJob* ) ) \
);
- job->start();
-}
-
-void StandardActionManager::slotCreateTag()
-{
- TagPropertiesDialog *dialog = new TagPropertiesDialog( d->m_parentWidget );
- if ( dialog->exec() == KDialog::Accepted ) {
- Tag newTag;
- newTag.setLabel( dialog->label() );
- newTag.setDescription( dialog->description() );
-
- TagCreateJob *job = d->m_tagProvider->tagCreateJob();
- job->setTag( newTag );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotTagCreated( KJob* ) \
) );
- job->start();
- }
-}
-
-void StandardActionManager::slotModifyTag()
-{
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<TagNode> tagNode = boost::dynamic_pointer_cast<TagNode, \
TreeNode>( treeNode );
- if ( !tagNode )
- return;
-
- Tag tag = tagNode->tag();
- TagPropertiesDialog *dialog = new TagPropertiesDialog( d->m_parentWidget );
- dialog->setLabel( tag.label() );
- dialog->setDescription( tag.description() );
- if ( dialog->exec() == KDialog::Accepted ) {
- tag.setLabel( dialog->label() );
- tag.setDescription( dialog->description() );
-
- TagModifyJob *job = d->m_tagProvider->tagModifyJob();
- job->setTag( tag );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotTagModified( KJob* \
) ) );
- job->start();
- }
-}
-
-void StandardActionManager::slotDeleteTag()
-{
- QModelIndex selectedIndex;
- if ( d->m_feedSelectionModel && d->m_feedSelectionModel->hasSelection() )
- selectedIndex = d->m_feedSelectionModel->selectedRows().first();
-
- const shared_ptr<TreeNode> treeNode = selectedIndex.data( \
FeedListModel::TreeNodeRole ).
- value<shared_ptr<TreeNode> >();
- const shared_ptr<TagNode> tagNode = boost::dynamic_pointer_cast<TagNode, \
TreeNode>( treeNode );
- if ( !tagNode )
- return;
-
- const Tag tag = tagNode->tag();
- TagDeleteJob *job = d->m_tagProvider->tagDeleteJob();
- job->setTag( tag );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotTagDeleted( KJob* ) ) \
);
- job->start();
-}
-
-void StandardActionManager::slotManageSubscriptions()
-{
- KDialog *dialog = new KDialog( d->m_parentWidget );
- dialog->setCaption( i18n( "Manage RSS subscriptions" ) );
- dialog->setButtons( KDialog::Ok | KDialog::Cancel );
-
-#ifdef TEMPORARILY_REMOVED
- FeedList *allFeeds = new FeedList( ResourceManager::self()->identifiers(), \
dialog );
- SubscriptionsModel *subscriptionsModel = new SubscriptionsModel( \
d->m_subscriptionLabel, dialog );
- subscriptionsModel->setFeedList( allFeeds );
- QTreeView *subscriptionsView = new QTreeView( dialog );
- subscriptionsView->setModel( subscriptionsModel );
- dialog->setMainWidget( subscriptionsView );
- dialog->setInitialSize( QSize( 400, 460 ) );
-
- if ( dialog->exec() == KDialog::Accepted ) {
- Q_FOREACH( Feed *feed, subscriptionsModel->unsubscribed() ) {
- kDebug() << "Unsubscribing from:" << feed->id() << ", title:" << \
feed->title();
- feed->removeSubscriptionLabel( d->m_subscriptionLabel );
- FeedModifyJob *job = new FeedModifyJob( static_cast<const Feed *> ( feed \
), this );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFeedModified( \
KJob* ) ) );
- job->start();
- }
- Q_FOREACH( Feed *feed, subscriptionsModel->subscribed() ) {
- kDebug() << "Subscribing to:" << feed->id() << ", title:" << \
feed->title();
- feed->addSubscriptionLabel( d->m_subscriptionLabel );
- FeedModifyJob *job = new FeedModifyJob( static_cast<const Feed *> ( feed \
), this );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotFeedModified( \
KJob* ) ) );
- job->start();
- }
- }
-
-#endif
-
- delete dialog;
-}
-
-void StandardActionManager::slotMarkItemRead()
-{
- QModelIndexList selectedIndexes;
- if ( d->m_itemSelectionModel && d->m_itemSelectionModel->hasSelection() )
- selectedIndexes = d->m_itemSelectionModel->selectedRows();
- else
- return;
-
- Q_FOREACH( const QModelIndex &selectedIndex, selectedIndexes ) {
- Item item = selectedIndex.data( ItemModel::ItemRole ).value<Item>();
-
- if ( !item.status().testFlag( KRss::Item::Unread ) )
- continue;
-
- // clear 'New' and 'Unread'
- item.setStatus( item.status() & KRss::Item::Unread );
- ItemModifyJob * const job = new ItemModifyJob();
- job->setItem( item );
- job->setIgnorePayload( true );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotItemModified( KJob* \
) ) );
- job->start();
- }
-}
-
-void StandardActionManager::slotMarkItemUnread()
-{
- QModelIndexList selectedIndexes;
- if ( d->m_itemSelectionModel && d->m_itemSelectionModel->hasSelection() )
- selectedIndexes = d->m_itemSelectionModel->selectedRows();
- else
- return;
-
- Q_FOREACH( const QModelIndex &selectedIndex, selectedIndexes ) {
- Item item = selectedIndex.data( ItemModel::ItemRole ).value<Item>();
-
- if ( item.status().testFlag( KRss::Item::Unread ) )
- continue;
-
- // set 'Unread'
- item.setStatus( item.status() | KRss::Item::Unread );
- ItemModifyJob * const job = new ItemModifyJob();
- job->setItem( item );
- job->setIgnorePayload( true );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotItemModified( KJob* \
) ) );
- job->start();
- }
-}
-
-void StandardActionManager::slotMarkItemImportant( bool checked )
-{
- QModelIndexList selectedIndexes;
- if ( d->m_itemSelectionModel && d->m_itemSelectionModel->hasSelection() )
- selectedIndexes = d->m_itemSelectionModel->selectedRows();
- else
- return;
-
- Q_FOREACH( const QModelIndex &selectedIndex, selectedIndexes ) {
- Item item = selectedIndex.data( ItemModel::ItemRole ).value<Item>();
-
- // set or clear 'Important' according to 'checked'
- ( checked ? item.setStatus( item.status() | KRss::Item::Important ) :
- item.setStatus( item.status() & ~KRss::Item::Important ) );
-
- ItemModifyJob * const job = new ItemModifyJob();
- job->setItem( item );
- job->setIgnorePayload( true );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotItemModified( KJob* \
) ) );
- job->start();
- }
-}
-
-void StandardActionManager::slotDeleteItem()
-{
- QModelIndexList selectedIndexes;
- if ( d->m_itemSelectionModel && d->m_itemSelectionModel->hasSelection() )
- selectedIndexes = d->m_itemSelectionModel->selectedRows();
- else
- return;
-
- Q_FOREACH( const QModelIndex &selectedIndex, selectedIndexes ) {
- const Item item = selectedIndex.data( ItemModel::ItemRole ).value<Item>();
- ItemDeleteJob * const job = new ItemDeleteJob();
- job->setItem( item );
- connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotItemDeleted( KJob* \
) ) );
- job->start();
- }
-}
-
-void StandardActionManager::slotNetFeedCreated( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not add a new feed: %1", \
job->errorString() ),
- i18n( "Feed creation failed" ) );
- }
-}
-
-
-void StandardActionManager::slotFeedModified( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not change feed's \
properties: %1", job->errorString() ),
- i18n( "Feed properties modification failed" ) );
- }
-}
-
-void StandardActionManager::slotFeedDeleted( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not delete the feed: %1", \
job->errorString() ),
- i18n( "Feed deletion failed" ) );
- }
-}
-
-void StandardActionManager::slotItemModified( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not change item's \
properties: %1", job->errorString() ),
- i18n( "Item properties modification failed" ) );
- }
-}
-
-void StandardActionManager::slotItemDeleted( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not delete the item: %1", \
job->errorString() ),
- i18n( "Item deletion failed" ) );
- }
-}
-
-void StandardActionManager::slotTagCreated( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not create tag: %1", \
job->errorString() ),
- i18n( "Tag creation failed" ) );
- }
-}
-
-void StandardActionManager::slotTagModified( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not modify tag: %1", \
job->errorString() ),
- i18n( "Tag modification failed" ) );
- }
-}
-
-void StandardActionManager::slotTagDeleted( KJob* job )
-{
- if ( job->error() ) {
- KMessageBox::error( d->m_parentWidget, i18n("Could not delete tag: %1", \
job->errorString() ),
- i18n( "Tag deletion failed" ) );
- }
-}
-
-#include "standardactionmanager.moc"
diff --git a/krss/standardactionmanager.h b/krss/standardactionmanager.h
deleted file mode 100644
index cfe46fd..0000000
--- a/krss/standardactionmanager.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- Copyright (C) 2008 Dmitry Ivanov <vonami@gmail.com>
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef KRSS_STANDARDACTIONMANAGER_H
-#define KRSS_STANDARDACTIONMANAGER_H
-
-#include "krss_export.h"
-
-#include <QtCore/QObject>
-
-class KAction;
-class KActionCollection;
-class KJob;
-class QItemSelectionModel;
-class QWidget;
-
-namespace boost {
-template <typename T> class shared_ptr;
-}
-
-namespace KRss {
-
-class TagProvider;
-class StandardActionManagerPrivate;
-
-class KRSS_EXPORT StandardActionManager : public QObject
-{
- Q_OBJECT
-
-public:
-
- enum Type {
- CreateNetFeed,
- FetchFeed,
- AbortFetch,
- FeedProperties,
- DeleteFeed,
- CreateTag,
- ModifyTag,
- DeleteTag,
- ManageSubscriptions,
- MarkItemNew,
- MarkItemRead,
- MarkItemUnread,
- MarkItemImportant,
- DeleteItem,
- LastType
- };
-
- explicit StandardActionManager( KActionCollection *actionCollection, QWidget \
*parent = 0 );
- ~StandardActionManager();
-
- void setFeedSelectionModel( QItemSelectionModel *selectionModel );
- void setItemSelectionModel( QItemSelectionModel *selectionModel );
- void setSubscriptionLabel( const QString &subscriptionLabel );
- void setTagProvider( const boost::shared_ptr<const TagProvider>& tagProvider );
- KAction* action( Type type );
- void createAllActions();
-
-private:
-
- //helper methods
- void enableAction( Type type, bool enable );
-
-private Q_SLOTS:
-
- void slotCreateNetFeed();
- void slotFetchFeed();
- void slotAbortFetch();
- void slotFeedProperties();
- void slotDeleteFeed();
- void slotCreateTag();
- void slotModifyTag();
- void slotDeleteTag();
- void slotManageSubscriptions();
- void slotMarkItemRead();
- void slotMarkItemUnread();
- void slotMarkItemImportant( bool checked );
- void slotDeleteItem();
- void updateActions();
-
- void slotNetFeedCreated( KJob* job );
- void slotFeedModified( KJob* job );
- void slotFeedDeleted( KJob* job );
- void slotItemModified( KJob* job );
- void slotItemDeleted( KJob* job );
- void slotTagCreated( KJob *job );
- void slotTagModified( KJob *job );
- void slotTagDeleted( KJob *job );
-
-private:
-
- Q_DISABLE_COPY( StandardActionManager )
- StandardActionManagerPrivate * const d;
-};
-
-} // namespace KRss
-
-#endif /* KRSS_STANDARDACTIONMANAGER_H */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic