From kde-commits Sat Mar 31 15:16:24 2012 From: Frank Osterfeld Date: Sat, 31 Mar 2012 15:16:24 +0000 To: kde-commits Subject: [kdepimlibs/akregator_port] krss: Move FeedListView from krss to Akregator. Message-Id: <20120331151624.6924BA6129 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=133320773207774 Git commit 5e8fa3b589ed80868dff303d6f77904a7c2eec03 by Frank Osterfeld. Committed on 24/02/2012 at 16:19. Pushed by osterfeld into branch 'akregator_port'. Move FeedListView from krss to Akregator. M +0 -3 krss/CMakeLists.txt D +0 -337 krss/ui/feedlistview.cpp D +0 -73 krss/ui/feedlistview.h http://commits.kde.org/kdepimlibs/5e8fa3b589ed80868dff303d6f77904a7c2eec03 diff --git a/krss/CMakeLists.txt b/krss/CMakeLists.txt index c6aade7..5395d84 100644 --- a/krss/CMakeLists.txt +++ b/krss/CMakeLists.txt @@ -23,7 +23,6 @@ set(krss_LIB_SRCS helper.cpp feeditemmodel.cpp # ui stuff - ui/feedlistview.cpp ui/feedpropertiesdialog.cpp ) = @@ -70,8 +69,6 @@ set(krss_LIB_HDRS ) = set(krss_UI_LIB_HDRS - ui/feedlistview.h - ui/netfeedcreatedialog.h ui/feedpropertiesdialog.h ) = diff --git a/krss/ui/feedlistview.cpp b/krss/ui/feedlistview.cpp deleted file mode 100644 index 6dd7e26..0000000 --- a/krss/ui/feedlistview.cpp +++ /dev/null @@ -1,337 +0,0 @@ -/* - Copyright (C) 2008 Dmitry Ivanov - 2007, 2009 Frank Osterfeld - - 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 . -*/ - -#include "feedlistview.h" -#include "krss/feeditemmodel.h" - -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include - -using namespace KRss; -using boost::shared_ptr; - -// helper functions -static QModelIndex prevIndex( const QModelIndex&idx ) -{ - if ( !idx.isValid() ) - return QModelIndex(); - const QAbstractItemModel* const model =3D idx.model(); - assert( model ); - - if ( idx.row() > 0 ) { - QModelIndex i =3D idx.sibling( idx.row() - 1, idx.column() ); - while ( model->hasChildren( i ) ) { - i =3D i.child( model->rowCount( i ) - 1, i.column() ); - } - return i; - } - else - return idx.parent(); -} - -static QModelIndex prevFeedIndex( const QModelIndex& idx, bool allowPassed= =3D false ) -{ - QModelIndex prev =3D allowPassed ? idx : prevIndex( idx ); - while ( prev.isValid() && prev.data( FeedItemModel::IsFolderRole ).toB= ool() ) { - prev =3D prevIndex( prev ); - } - return prev; -} - -static QModelIndex prevUnreadFeedIndex( const QModelIndex& idx, bool allow= Passed =3D false ) -{ - QModelIndex prev =3D allowPassed ? idx : prevIndex( idx ); - while ( prev.isValid() && ( prev.data( FeedItemModel::IsFolderRole ).t= oBool() || - prev.sibling( prev.row(), FeedItemModel::UnreadCountColumn ).d= ata().toInt() =3D=3D 0 ) ) { - prev =3D prevIndex( prev ); - } - return prev; -} - -static QModelIndex lastLeaveChild( const QAbstractItemModel* const model ) -{ - assert( model ); - if ( model->rowCount() =3D=3D 0 ) - return QModelIndex(); - QModelIndex idx =3D model->index( model->rowCount() - 1, 0 ); - while ( model->hasChildren( idx ) ) { - idx =3D idx.child( model->rowCount( idx ) - 1, idx.column() ); - } - return idx; -} - -static QModelIndex nextIndex( const QModelIndex& idx ) -{ - if ( !idx.isValid() ) - return QModelIndex(); - const QAbstractItemModel* const model =3D idx.model(); - assert( model ); - if ( model->hasChildren( idx ) ) - return idx.child( 0, idx.column() ); - QModelIndex i =3D idx; - while ( true ) { - if ( !i.isValid() ) - return i; - const int siblings =3D model->rowCount( i.parent() ); - if ( i.row() + 1 < siblings ) - return i.sibling( i.row() + 1, i.column() ); - i =3D i.parent(); - } -} - -static QModelIndex nextFeedIndex( const QModelIndex& idx ) -{ - QModelIndex next =3D nextIndex( idx ); - while ( next.isValid() && next.data( FeedItemModel::IsFolderRole ).toB= ool() ) { - next =3D nextIndex( next ); - } - return next; -} - -static QModelIndex nextUnreadFeedIndex( const QModelIndex& idx ) -{ - QModelIndex next =3D nextIndex( idx ); - while ( next.isValid() && ( next.data( FeedItemModel::IsFolderRole ).t= oBool() || - next.sibling( next.row(), FeedItemModel::UnreadCountColumn ).d= ata().toInt() =3D=3D 0 ) ) { - next =3D nextIndex( next ); - } - return next; -} - -class KRss::FeedListView::Private -{ - FeedListView* const q; -public: - - explicit Private( FeedListView* ); - ~Private() { - saveHeaderSettings(); - } - - QByteArray headerState; - KConfigGroup configGroup; - - void loadHeaderSettings(); - void saveHeaderSettings(); - void slotClicked( const QModelIndex& index ); - void slotActivated( const QModelIndex& index ); - void showHeaderMenu( const QPoint& ); - void headerMenuItemTriggered( QAction* action ); - -}; - -FeedListView::Private::Private( FeedListView* qq ) : q( qq ) -{ -} - -void FeedListView::Private::slotClicked( const QModelIndex &index ) -{ -#ifdef KRSS_PORT_REMOVED - emit q->clicked( q->model()->data( index, FeedItemModel::TreeNodeRole = ).value >() ); -#endif -} - -void FeedListView::Private::slotActivated( const QModelIndex &index ) -{ -#ifdef KRSS_PORT_REMOVED - emit q->clicked( q->model()->data( index, FeedItemModel::TreeNodeRole = ).value >() ); -#endif -} - -void FeedListView::Private::showHeaderMenu( const QPoint& pos ) -{ - if( ! q->model() ) - return; - - QPointer menu =3D new KMenu( q ); - menu->addTitle( i18n( "Columns" ) ); - menu->setAttribute( Qt::WA_DeleteOnClose ); - q->connect(menu, SIGNAL(triggered(QAction*)), q, SLOT(headerMenuItemTr= iggered(QAction*)) ); - - for (int i =3D 0; i < q->model()->columnCount(); ++i) - { - const QString col =3D q->model()->headerData( i, Qt::Horizontal, Q= t::DisplayRole ).toString(); - QAction* act =3D menu->addAction( col ); - act->setCheckable( true ); - act->setChecked( !q->header()->isSectionHidden( i ) ); - act->setData( i ); - } - - menu->popup( q->header()->mapToGlobal( pos ) ); -} - -void FeedListView::Private::loadHeaderSettings() -{ - if ( !configGroup.isValid() ) - return; - headerState =3D QByteArray::fromBase64( configGroup.readEntry( "FeedLi= stHeaders" ).toAscii() ); - q->header()->restoreState( headerState ); // needed, even with = Qt 4.5 -} - -void FeedListView::Private::saveHeaderSettings() -{ - if ( q->model() ) - headerState =3D q->header()->saveState(); - if ( configGroup.isValid() ) - configGroup.writeEntry( "FeedListHeaders", headerState.toBase64() = ); -} - -FeedListView::FeedListView( QWidget *parent ) - : Akonadi::EntityTreeView( parent ), d( new Private( this ) ) -{ - setSelectionMode( QAbstractItemView::SingleSelection ); - setSelectionBehavior( QAbstractItemView::SelectRows ); - setAlternatingRowColors( true ); - setContextMenuPolicy( Qt::CustomContextMenu ); - setDragDropMode( QAbstractItemView::DragDrop ); - setDropIndicatorShown( true ); - setAcceptDrops( true ); - setUniformRowHeights( true ); - Akonadi::CollectionStatisticsDelegate* delegate =3D new Akonadi::Colle= ctionStatisticsDelegate( this ); - delegate->setProgressAnimationEnabled( true ); - delegate->setUnreadCountShown( true ); - setItemDelegate( delegate ); - connect( header(), SIGNAL(customContextMenuRequested(QPoint)), this, S= LOT(showHeaderMenu(QPoint)) ); - connect( this, SIGNAL(clicked(QModelIndex)), - this, SLOT(slotClicked(QModelIndex)) ); - connect( this, SIGNAL(activated(QModelIndex)), - this, SLOT( slotActivated(QModelIndex)) ); - - d->loadHeaderSettings(); -} - -KConfigGroup FeedListView::configGroup() const { - return d->configGroup; -} - -void FeedListView::setConfigGroup( const KConfigGroup& g ) { - d->configGroup =3D g; - d->loadHeaderSettings(); -} - -FeedListView::~FeedListView() -{ - delete d; -} - -void FeedListView::setModel( QAbstractItemModel* m ) -{ - if ( model() ) - d->headerState =3D header()->saveState(); - - EntityTreeView::setModel( m ); - - if ( m ) - header()->restoreState( d->headerState ); - -#ifdef KRSS_PORT_DISABLED - QStack stack; - stack.push( rootIndex() ); - while ( !stack.isEmpty() ) - { - const QModelIndex i =3D stack.pop(); - const int childCount =3D m->rowCount( i ); - for ( int j =3D 0; j < childCount; ++j ) - { - const QModelIndex child =3D m->index( j, 0, i ); - if ( child.isValid() ) - stack.push( child ); - } - setExpanded( i, i.data( Akregator::SubscriptionListModel::IsOpenRo= le ).toBool() ); - } -#endif // KRSS_PORT_DISABLED - - header()->setContextMenuPolicy( Qt::CustomContextMenu ); -} - -void FeedListView::Private::headerMenuItemTriggered( QAction* action ) -{ - assert( action ); - const int col =3D action->data().toInt(); - if ( action->isChecked() ) - q->header()->showSection( col ); - else - q->header()->hideSection( col ); -} - - -void FeedListView::slotPrevFeed() -{ - if ( !model() ) - return; - const QModelIndex current =3D currentIndex(); - QModelIndex prev =3D prevFeedIndex( current ); - if ( !prev.isValid() ) - prev =3D prevFeedIndex( lastLeaveChild( model() ), true ); - if ( prev.isValid() ) - setCurrentIndex( prev ); -} - -void FeedListView::slotNextFeed() -{ - if ( !model() ) - return; - const QModelIndex current =3D currentIndex(); - QModelIndex next =3D nextFeedIndex( current ); - if ( !next.isValid() ) - next =3D nextFeedIndex( model()->index( 0, 0 ) ); - if ( next.isValid() ) - setCurrentIndex( next ); -} - -void FeedListView::slotPrevUnreadFeed() -{ - if ( !model() ) - return; - const QModelIndex current =3D currentIndex(); - QModelIndex prev =3D prevUnreadFeedIndex( current ); - if ( !prev.isValid() ) - prev =3D prevUnreadFeedIndex( lastLeaveChild( model() ), true ); - if ( prev.isValid() ) - setCurrentIndex( prev ); -} - -void FeedListView::slotNextUnreadFeed() -{ - if ( !model() ) - return; - const QModelIndex current =3D currentIndex(); - QModelIndex next =3D nextUnreadFeedIndex( current ); - if ( !next.isValid() ) - next =3D nextUnreadFeedIndex( model()->index( 0, 0 ) ); - if ( next.isValid() ) - setCurrentIndex( next ); -} - -void FeedListView::scrollToCollection( const Akonadi::Collection& c, QAbst= ractItemView::ScrollHint hint ) { - Q_UNUSED( c ) - Q_UNUSED( hint ) - //TODO -} - -#include "feedlistview.moc" diff --git a/krss/ui/feedlistview.h b/krss/ui/feedlistview.h deleted file mode 100644 index cb0c19f..0000000 --- a/krss/ui/feedlistview.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (C) 2008 Dmitry Ivanov - 2007, 2009 Frank Osterfeld - - 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 . -*/ - -#ifndef KRSS_FEEDLISTVIEW_H -#define KRSS_FEEDLISTVIEW_H - -#include "krss/krss_export.h" - -#include - -#include - -class KConfigGroup; - -namespace Akonadi { - class Collection; -} -namespace KRss { - -class KRSS_EXPORT FeedListView : public Akonadi::EntityTreeView -{ - Q_OBJECT - -public: - - explicit FeedListView( QWidget *parent =3D 0 ); - ~FeedListView(); - - /* reimp */ void setModel( QAbstractItemModel* model ); - - KConfigGroup configGroup() const; - void setConfigGroup( const KConfigGroup& group); - - void scrollToCollection( const Akonadi::Collection& c, QAbstractItemVi= ew::ScrollHint hint=3DEnsureVisible ); - -public Q_SLOTS: - void slotPrevFeed(); - void slotNextFeed(); - void slotPrevUnreadFeed(); - void slotNextUnreadFeed(); - -Q_SIGNALS: - - void clicked( const Akonadi::Collection& ); - void activated( const Akonadi::Collection& ); - -private: - class Private; - Private* const d; - Q_PRIVATE_SLOT( d, void slotClicked( const QModelIndex& ) ) - Q_PRIVATE_SLOT( d, void slotActivated( const QModelIndex& ) ) - Q_PRIVATE_SLOT( d, void showHeaderMenu( const QPoint& ) ) - Q_PRIVATE_SLOT( d, void headerMenuItemTriggered( QAction* ) ) -}; - -} // namespace KRss - -#endif // KRSS_FEEDLISTVIEW_H