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

List:       kde-commits
Subject:    [kdepim/work/akonadi-ports] /: implement mark all as read (for
From:       Frank Osterfeld <frank.osterfeld () kdab ! com>
Date:       2011-09-18 15:06:00
Message-ID: 20110918150600.C55CBA607A () git ! kde ! org
[Download RAW message or body]

Git commit f8ce13845c1a3768c255777406d621daf634fce4 by Frank Osterfeld.
Committed on 18/09/2011 at 16:55.
Pushed by osterfeld into branch 'work/akonadi-ports'.

implement mark all as read (for single feeds for now)

M  +1    -0    akregator/src/CMakeLists.txt
M  +11   -0    akregator/src/mainwidget.cpp
A  +109  -0    akregator/src/modifycommands.cpp     [License: GPL (v2+) (+Qt \
exception)] A  +59   -0    akregator/src/modifycommands.h     [License: GPL (v2+) \
(+Qt exception)] M  +16   -6    krss/krss/item.cpp
M  +2    -0    krss/krss/item.h

http://commits.kde.org/kdepim/f8ce13845c1a3768c255777406d621daf634fce4

diff --git a/akregator/src/CMakeLists.txt b/akregator/src/CMakeLists.txt
index 2d385f4..f74a695 100644
--- a/akregator/src/CMakeLists.txt
+++ b/akregator/src/CMakeLists.txt
@@ -89,6 +89,7 @@ set(akregatorpart_PART_SRCS
    tabwidget.cpp
 #   progressmanager.cpp
    kernel.cpp
+   modifycommands.cpp
    akregator_part.cpp
    mainwidget.cpp
    notificationmanager.cpp
diff --git a/akregator/src/mainwidget.cpp b/akregator/src/mainwidget.cpp
index 0bffb6f..66f7bbf 100644
--- a/akregator/src/mainwidget.cpp
+++ b/akregator/src/mainwidget.cpp
@@ -34,6 +34,7 @@
 #include "browserframe.h"
 #include "createfeedcommand.h"
 #include "createtagcommand.h"
+#include "modifycommands.h"
 #include "deletesubscriptioncommand.h"
 #include "editsubscriptioncommand.h"
 #include "importfeedlistcommand.h"
@@ -729,6 +730,16 @@ void Akregator::MainWidget::slotMarkAllFeedsRead()
 
 void Akregator::MainWidget::slotMarkFeedRead()
 {
+    const Akonadi::Collection c = m_selectionController->selectedCollection();
+    if ( !c.isValid() )
+        return;
+    MarkAsReadCommand* cmd = new MarkAsReadCommand( this );
+
+    cmd->setCollection( c );
+    cmd->setSession( m_session );
+    connect( cmd, SIGNAL( result( KJob* ) ), this, SLOT( slotJobFinished( KJob* ) ) \
); +    d->setUpAndStart( cmd );
+
 #ifdef KRSS_PORT_DISABLED
     const shared_ptr<KRss::TreeNode> treeNode = \
m_selectionController->selectedSubscription();  if ( !treeNode )
diff --git a/akregator/src/modifycommands.cpp b/akregator/src/modifycommands.cpp
new file mode 100644
index 0000000..9986902
--- /dev/null
+++ b/akregator/src/modifycommands.cpp
@@ -0,0 +1,109 @@
+/*
+    This file is part of Akregator.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+    As a special exception, permission is given to link this program
+    with any edition of Qt, and distribute the resulting executable,
+    without including the source code for Qt in the source distribution.
+*/
+
+#include "modifycommands.h"
+
+#include <krss/feedcollection.h>
+#include <krss/item.h>
+
+#include <Akonadi/Collection>
+#include <Akonadi/ItemFetchJob>
+#include <Akonadi/ItemModifyJob>
+#include <Akonadi/Session>
+
+#include <KLocalizedString>
+
+#include <QPointer>
+
+using namespace Akonadi;
+using namespace Akregator;
+
+class MarkAsReadCommand::Private {
+public:
+
+    Private() : session( 0 ) {}
+    KRss::FeedCollection collection;
+    QPointer<Akonadi::Session> session;
+};
+
+MarkAsReadCommand::MarkAsReadCommand( QObject* parent )
+    : Command( parent )
+    , d( new Private )
+{
+}
+
+void MarkAsReadCommand::setCollection( const Collection& c ) {
+    d->collection = c;
+}
+
+void MarkAsReadCommand::setSession( Session* s ) {
+    d->session = s;
+}
+
+void MarkAsReadCommand::doStart() {
+    Q_ASSERT( d->session );
+
+    if ( !d->collection.isValid() ) {
+        setErrorText( i18n("Invalid collection.") );
+        emitResult();
+        return;
+    }
+
+    ItemFetchJob* job = new ItemFetchJob( d->collection, d->session );
+    connect( job, SIGNAL(finished(KJob*)), this, SLOT(itemsFetched(KJob*)) );
+    job->start();
+}
+
+void MarkAsReadCommand::itemsFetched( KJob* j ) {
+    if ( j->error() ) {
+        setErrorText( i18n("Could not fetch items for collection %1: %2", \
d->collection.title(), j->errorString() ) ); +        emitResult();
+        return;
+    }
+
+    const ItemFetchJob * const fjob = qobject_cast<const ItemFetchJob*>( j );
+    Q_ASSERT( fjob );
+
+    Akonadi::Item::List items = fjob->items();
+    if (items.isEmpty() ) {
+        emitResult();
+        return;
+    }
+
+    Akonadi::Item::List::Iterator it = items.begin();
+    for ( ; it != items.end(); ++it )
+        KRss::Item::setStatus( *it, KRss::Item::status( *it ) & ~KRss::Item::Unread \
); +
+    ItemModifyJob* mjob = new ItemModifyJob( items, d->session );
+    connect( mjob, SIGNAL(finished(KJob*)), this, SLOT(itemsModified(KJob*)) );
+    mjob->start();
+}
+
+void MarkAsReadCommand::itemsModified( KJob* j ) {
+    if ( j->error() ) {
+        setErrorText( i18n("Could not mark items as read: %1", j->errorString() ) );
+    }
+
+    emitResult();
+}
diff --git a/akregator/src/modifycommands.h b/akregator/src/modifycommands.h
new file mode 100644
index 0000000..a7b3ebd
--- /dev/null
+++ b/akregator/src/modifycommands.h
@@ -0,0 +1,59 @@
+/*
+    This file is part of Akregator.
+
+    Copyright (C) 2011 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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+    As a special exception, permission is given to link this program
+    with any edition of Qt, and distribute the resulting executable,
+    without including the source code for Qt in the source distribution.
+*/
+
+#ifndef AKREGATOR_MODIFYCOMMANDS_H
+#define AKREGATOR_MODIFYCOMMANDS_H
+
+#include "command.h"
+
+namespace Akonadi {
+   class Collection;
+   class Session;
+}
+
+namespace Akregator {
+class MarkAsReadCommand : public Command {
+    Q_OBJECT
+public:
+    explicit MarkAsReadCommand( QObject* parent=0 );
+
+    void setCollection( const Akonadi::Collection& c );
+    void setSession( Akonadi::Session* s );
+
+private:
+    void doStart();
+
+private Q_SLOTS:
+    void itemsFetched( KJob* );
+    void itemsModified( KJob* );
+
+private:
+    class Private;
+    Private* const d;
+};
+
+}
+
+#endif
+
diff --git a/krss/krss/item.cpp b/krss/krss/item.cpp
index 931ad95..04cf12d 100644
--- a/krss/krss/item.cpp
+++ b/krss/krss/item.cpp
@@ -333,22 +333,27 @@ void Item::setHash( int hash )
     d->akonadiItem.setPayload<RssItem>( payload );
 }
 
-Item::Status Item::status() const
+Item::Status Item::status( const Akonadi::Item& aitem )
 {
     //PENDING(frank) this looks like a candidate for caching
     Status stat;
-    if ( !d->akonadiItem.hasFlag( RssItem::flagRead() ) )
+    if ( !aitem.hasFlag( RssItem::flagRead() ) )
         stat |= Item::Unread;
 
-    if ( d->akonadiItem.hasFlag( RssItem::flagImportant() ) )
+    if ( aitem.hasFlag( RssItem::flagImportant() ) )
         stat |= Item::Important;
 
-    if ( d->akonadiItem.hasFlag( RssItem::flagDeleted() ) )
+    if ( aitem.hasFlag( RssItem::flagDeleted() ) )
         stat |= Item::Deleted;
 
     return stat;
 }
 
+Item::Status Item::status() const
+{
+    return status( d->akonadiItem );
+}
+
 bool Item::isImportant() const
 {
     return RssItem::isImportant( d->akonadiItem );
@@ -369,7 +374,7 @@ bool Item::isDeleted() const
     return RssItem::isDeleted( d->akonadiItem );
 }
 
-void Item::setStatus( const Item::Status& stat )
+void Item::setStatus( Akonadi::Item& aitem, const Item::Status& stat )
 {
     Akonadi::Item::Flags flags;
     if ( !stat.testFlag( Item::Unread ) )
@@ -381,7 +386,12 @@ void Item::setStatus( const Item::Status& stat )
     if ( stat.testFlag( Item::Deleted ) )
         flags.insert( RssItem::flagDeleted() );
 
-    d->akonadiItem.setFlags( flags );
+    aitem.setFlags( flags );
+}
+
+void Item::setStatus( const Item::Status& stat )
+{
+    setStatus( d->akonadiItem, stat );
 }
 
 int Item::sourceFeedId() const
diff --git a/krss/krss/item.h b/krss/krss/item.h
index 91f8a05..1369182 100644
--- a/krss/krss/item.h
+++ b/krss/krss/item.h
@@ -82,7 +82,9 @@ public:
     QList<TagId> tags() const;
     void setTags( const QList<TagId>& tags );
 
+    static Item::Status status( const Akonadi::Item& aitem );
     Item::Status status() const;
+    static void setStatus( Akonadi::Item& aitem, const Item::Status& stat );
     void setStatus( const Item::Status& stat );
 
     bool isImportant() const;


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

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