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

List:       kde-commits
Subject:    [kdepimlibs/akregator_port] krss: start a new EntityTreeModel-based model for our stuff
From:       Frank Osterfeld <frank.osterfeld () kdemail ! net>
Date:       2012-03-31 15:16:22
Message-ID: 20120331151622.4FAFFA60F7 () git ! kde ! org
[Download RAW message or body]

Git commit be79294e05716c313f8d04ce0b072acf8d1c0732 by Frank Osterfeld.
Committed on 17/10/2009 at 11:02.
Pushed by osterfeld into branch 'akregator_port'.

start a new EntityTreeModel-based model for our stuff

svn path=/branches/work/akonadi-ports/kdepim/; revision=1036391

M  +2    -0    krss/CMakeLists.txt
A  +151  -0    krss/feeditemmodel.cpp     [License: GPL (v2+)]
A  +79   -0    krss/feeditemmodel.h     [License: GPL (v2+)]

http://commits.kde.org/kdepimlibs/be79294e05716c313f8d04ce0b072acf8d1c0732

diff --git a/krss/CMakeLists.txt b/krss/CMakeLists.txt
index a3332ad..1d37b11 100644
--- a/krss/CMakeLists.txt
+++ b/krss/CMakeLists.txt
@@ -42,6 +42,7 @@ set(krss_LIB_SRCS
    dbushelper.cpp
    helper.cpp
    itemmodel.cpp
+   feeditemmodel.cpp
    treenode.cpp
    treenodevisitor.cpp
    feedlistmodel.cpp
@@ -133,6 +134,7 @@ set(krss_LIB_HDRS
    feedlist.h
    itemlisting.h
    itemlistjob.h
+   feeditemmodel.h 
    itemmodel.h
    importitemsjob.h
    importopmljob.h
diff --git a/krss/feeditemmodel.cpp b/krss/feeditemmodel.cpp
new file mode 100644
index 0000000..0dce9a1
--- /dev/null
+++ b/krss/feeditemmodel.cpp
@@ -0,0 +1,151 @@
+/*
+    Copyright (C) 2009    Frank Osterfeld <osterfeld@kde.org>
+
+    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 "feeditemmodel.h"
+#include "rssitem.h"
+#include "person.h"
+
+#include <KDateTime>
+#include <KGlobal>
+#include <KIcon>
+#include <KLocale>
+
+using namespace Akonadi;
+using namespace KRss;
+
+class KRss::FeedItemModelPrivate {
+    FeedItemModel* const q;
+public:
+    explicit FeedItemModelPrivate( FeedItemModel* qq ) : q( qq ), importantIcon( \
KIcon( QLatin1String("mail-mark-important") ) ) { +
+    }
+
+    KIcon importantIcon;
+};
+
+
+FeedItemModel::FeedItemModel( Session* session, ChangeRecorder* monitor, QObject* \
parent ) : EntityTreeModel( session, monitor, parent ), d( new FeedItemModelPrivate( \
this ) ) { +    setItemPopulationStrategy( EntityTreeModel::LazyPopulation );
+}
+
+FeedItemModel::~FeedItemModel() {
+    delete d;
+}
+
+QVariant FeedItemModel::getData( const Akonadi::Item &akonadiItem, int column, int \
role ) const { +    if ( !akonadiItem.hasPayload<RssItem>() )
+        return QVariant();
+
+    const RssItem item = akonadiItem.payload<RssItem>();
+    if ( role == SortRole && column == DateColumn )
+        return item.dateUpdated().toTime_t();
+
+    if ( role == IsDeletedRole )
+        return false;
+
+    if ( role == Qt::DisplayRole || role == SortRole ) {
+        QString authors;
+        switch ( 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( akonadiItem );
+        return var;
+    }
+
+    if ( role == IsImportantRole )
+        return RssItem::isImportant( akonadiItem );
+
+    if ( role == IsNewRole )
+        return RssItem::isNew( akonadiItem );
+
+    if ( role == IsUnreadRole )
+        return RssItem::isUnread( akonadiItem );
+
+    if ( role == IsReadRole )
+        return RssItem::isRead( akonadiItem );
+
+    if ( role == IsDeletedRole )
+        return RssItem::isDeleted( akonadiItem );
+
+    if ( role == LinkRole )
+        return item.link();
+
+    //PENDING(frank) TODO: use configurable colors
+    if ( role == Qt::ForegroundRole ) {
+        if ( RssItem::isNew( akonadiItem ) )
+            return Qt::red;
+        if ( RssItem::isUnread( akonadiItem ) )
+            return Qt::blue;
+    }
+
+    if ( role == Qt::DecorationRole && column == ItemTitleColumn )
+        return RssItem::isImportant( akonadiItem ) ? d->importantIcon : QVariant();
+    return QVariant();
+}
+
+QVariant FeedItemModel::getData( const Collection &collection, int column, int role \
) const { +    return EntityTreeModel::getData( collection, column, role );
+}
+
+int FeedItemModel::columnCount( const QModelIndex& index ) const {
+    Q_UNUSED( index );
+    return ItemColumnCount;
+}
+
+QVariant FeedItemModel::getHeaderData( int section, Qt::Orientation orientation, int \
role, int headerSet ) const { +    if ( orientation != Qt::Horizontal )
+        return QVariant();
+    if ( role != Qt::DisplayRole )
+        return QVariant();
+    if ( headerSet == ItemListHeaders ) {
+        if ( section >= ItemColumnCount )
+            return QVariant();
+        switch ( section ) {
+        case ItemTitleColumn:
+            return i18n("Title");
+        case AuthorsColumn:
+            return i18n("Author");
+        case DateColumn:
+            return i18n("Date");
+        case FeedTitleColumn:
+            return i18n("Feed");
+        }
+    }
+    return QVariant();
+}
+
diff --git a/krss/feeditemmodel.h b/krss/feeditemmodel.h
new file mode 100644
index 0000000..13511ba
--- /dev/null
+++ b/krss/feeditemmodel.h
@@ -0,0 +1,79 @@
+/*
+    Copyright (C) 2009    Frank Osterfeld <osterfeld@kde.org>
+
+    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_FEEDITEMMODEL_H
+#define KRSS_FEEDITEMMODEL_H
+
+#include "krss_export.h"
+#include "item.h"
+
+#include <Akonadi/EntityTreeModel>
+
+class KJob;
+
+namespace KRss {
+
+class FeedItemModelPrivate;
+
+class KRSS_EXPORT FeedItemModel : public Akonadi::EntityTreeModel
+{
+    Q_OBJECT
+
+public:
+
+    enum ItemColumn {
+        ItemTitleColumn = 0,
+        AuthorsColumn,
+        DateColumn,
+        FeedTitleColumn,
+        ItemColumnCount
+    };
+
+    enum Role {
+        ItemRole = Qt::UserRole,
+        SortRole,
+        IsNewRole,
+        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 FeedItemModel( Akonadi::Session *session, Akonadi::ChangeRecorder* \
monitor, QObject* parent = 0 ); +    ~FeedItemModel();
+
+    /* reimp */ QVariant getData( const Akonadi::Item& item, int column, int \
role=Qt::DisplayRole ) const; +
+    /* reimp */ QVariant getData( const Akonadi::Collection& collection, int column, \
int role=Qt::DisplayRole ) const; +
+    /* reimp */ int columnCount( const QModelIndex& index = QModelIndex() ) const;
+
+    /* reimp */ QVariant getHeaderData( int section, Qt::Orientation orientation, \
int role, int headerSet ) const; +
+private:
+    friend class ::KRss::FeedItemModelPrivate;
+    FeedItemModelPrivate* const d;
+};
+
+} // namespace KRss
+
+Q_DECLARE_METATYPE(KRss::Item)
+
+#endif // KRSS_FEEDITEMMODEL_H


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

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