1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-16 02:54:33 +02:00

* InboxModel is now tree-aware.

This commit is contained in:
Christian Muehlhaeuser
2014-08-23 13:38:18 +02:00
parent 807ae19b2d
commit 8a46f65e31
2 changed files with 25 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013, Teo Mrnjavac <teo@kde.org> * Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -54,22 +55,32 @@ InboxModel::~InboxModel()
int int
InboxModel::unlistenedCount() const InboxModel::unlistenedCount( const QModelIndex& parent ) const
{ {
int count = 0; int count = 0;
foreach ( const Tomahawk::plentry_ptr& plentry, playlistEntries() ) for ( int i = 0; i < rowCount( parent ); i++ )
{ {
bool isUnlistened = true; const QModelIndex idx = index( i, 0, parent );
foreach ( Tomahawk::SocialAction sa, plentry->query()->queryTrack()->allSocialActions() )
PlayableItem* item = itemFromIndex( idx );
if ( item && item->source() )
{ {
if ( sa.action == "Inbox" && sa.value.toBool() == false ) count += unlistenedCount( idx );
{ }
isUnlistened = false; else if ( item && item->query() )
break; {
} bool isUnlistened = true;
foreach ( Tomahawk::SocialAction sa, item->query()->queryTrack()->allSocialActions() )
{
if ( sa.action == "Inbox" && sa.value.toBool() == false )
{
isUnlistened = false;
break;
}
}
if ( isUnlistened )
count++;
} }
if ( isUnlistened )
count++;
} }
return count; return count;
} }
@@ -148,7 +159,7 @@ void
InboxModel::removeIndex( const QModelIndex& index, bool moreToCome ) InboxModel::removeIndex( const QModelIndex& index, bool moreToCome )
{ {
PlayableItem* item = itemFromIndex( index ); PlayableItem* item = itemFromIndex( index );
if ( item && !item->query().isNull() ) if ( item && item->query() )
{ {
Tomahawk::DatabaseCommand_DeleteInboxEntry* cmd = new Tomahawk::DatabaseCommand_DeleteInboxEntry( item->query() ); Tomahawk::DatabaseCommand_DeleteInboxEntry* cmd = new Tomahawk::DatabaseCommand_DeleteInboxEntry( item->query() );
Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) ); Tomahawk::Database::instance()->enqueue( Tomahawk::dbcmd_ptr( cmd ) );

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2013, Teo Mrnjavac <teo@kde.org> * Copyright 2013, Teo Mrnjavac <teo@kde.org>
* Copyright 2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -32,7 +33,7 @@ public:
explicit InboxModel( QObject* parent = 0 ); explicit InboxModel( QObject* parent = 0 );
virtual ~InboxModel(); virtual ~InboxModel();
virtual int unlistenedCount() const; virtual int unlistenedCount( const QModelIndex& parent = QModelIndex() ) const;
public slots: public slots:
/** /**