1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Added unlistened count to Inbox item in sources view.

This commit is contained in:
Teo Mrnjavac 2013-04-23 03:41:08 +02:00
parent f9edc04b04
commit 024a1f74b3
8 changed files with 187 additions and 5 deletions

View File

@ -52,6 +52,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
sourcetree/items/TemporaryPageItem.cpp
sourcetree/items/GroupItem.cpp
sourcetree/items/HistoryItem.cpp
sourcetree/items/InboxItem.cpp
TomahawkTrayIcon.cpp
AudioControls.cpp

View File

@ -45,6 +45,28 @@ InboxModel::~InboxModel()
{}
int
InboxModel::unlistenedCount() const
{
int count = 0;
foreach ( const Tomahawk::plentry_ptr& plentry, playlistEntries() )
{
bool isUnlistened = true;
foreach ( Tomahawk::SocialAction sa, plentry->query()->queryTrack()->allSocialActions() )
{
if ( sa.action == "Inbox" && sa.value.toBool() == false )
{
isUnlistened = false;
break;
}
}
if ( isUnlistened )
count++;
}
return count;
}
QList<Tomahawk::SocialAction>
InboxModel::mergeSocialActions( QList<Tomahawk::SocialAction> first, QList<Tomahawk::SocialAction> second)
{

View File

@ -31,6 +31,8 @@ public:
explicit InboxModel( QObject* parent = 0 );
virtual ~InboxModel();
virtual int unlistenedCount() const;
public slots:
/**
* Reimplemented from PlaylistModel, all track insertions/appends go through this method.

View File

@ -28,6 +28,7 @@
#include "items/CategoryItems.h"
#include "items/TemporaryPageItem.h"
#include "items/ScriptCollectionItem.h"
#include "items/InboxItem.h"
#include "audio/AudioEngine.h"
#include "AnimationHelper.h"
@ -638,7 +639,36 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
if ( !index.parent().parent().isValid() )
o.rect.adjust( 7, 0, 0, 0 );
if ( type == SourcesModel::TemporaryPage )
if ( type == SourcesModel::Inbox )
{
InboxItem* ii = qobject_cast< InboxItem* >( item );
if ( ii && ii->unlistenedCount() )
{
painter->setRenderHint( QPainter::Antialiasing );
QFont figFont = option.font;
figFont.setFamily( "Arial Bold" );
figFont.setWeight( QFont::Black );
figFont.setPointSize( option.font.pointSize() - 1 );
QString count = QString::number( ii->unlistenedCount() );
int figWidth = QFontMetrics( figFont ).width( count );
QRect figRect = option.rect.adjusted( option.rect.width() - figWidth - 13, 0, -14, -option.rect.height() + option.fontMetrics.height() * 1.1 );
int hd = ( option.rect.height() - figRect.height() ) / 2;
figRect.adjust( 0, hd, 0, hd );
painter->setFont( figFont );
QColor figColor( 239, 140, 51 );
painter->setPen( figColor );
painter->setBrush( figColor );
TomahawkUtils::drawBackgroundAndNumbers( painter, count, figRect );
}
QStyledItemDelegate::paint( painter, o, index );
}
else if ( type == SourcesModel::TemporaryPage )
{
TemporaryPageItem* gpi = qobject_cast< TemporaryPageItem* >( item );
Q_ASSERT( gpi );

View File

@ -32,6 +32,7 @@
#include "sourcetree/items/GenericPageItems.h"
#include "sourcetree/items/HistoryItem.h"
#include "sourcetree/items/LovedTracksItem.h"
#include "sourcetree/items/InboxItem.h"
#include "SourceList.h"
#include "Playlist.h"
#include "collection/Collection.h"
@ -326,9 +327,7 @@ SourcesModel::appendGroups()
boost::bind( &ViewManager::newReleasesWidget, ViewManager::instance() ) );
newReleases->setSortValue( 5 );
GenericPageItem* inbox = new GenericPageItem( this, browse, tr( "Inbox" ), ImageRegistry::instance()->icon( RESPATH "images/inbox.svg" ),
boost::bind( &ViewManager::showInboxPage, ViewManager::instance() ),
boost::bind( &ViewManager::inboxWidget, ViewManager::instance() ) );
InboxItem* inbox = new InboxItem( this, browse );
inbox->setSortValue( 6 );
m_collectionsGroup = new GroupItem( this, m_rootItem, tr( "Friends" ), 4 );

View File

@ -63,7 +63,8 @@ public:
TemporaryPage = 7,
LovedTracksPage = 10,
ScriptCollection = 11
ScriptCollection = 11,
Inbox = 12
};
enum CategoryType {

View File

@ -0,0 +1,81 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "InboxItem.h"
#include "utils/ImageRegistry.h"
#include "ViewManager.h"
#include "ViewPage.h"
#include "playlist/InboxModel.h"
#include <QString>
#include <QIcon>
InboxItem::InboxItem( SourcesModel* model, SourceTreeItem* parent )
: SourceTreeItem( model, parent, SourcesModel::Inbox )
, m_sortValue( -150 )
{}
InboxItem::~InboxItem()
{}
QString
InboxItem::text() const
{
return tr( "Inbox" );
}
QIcon
InboxItem::icon() const
{
return ImageRegistry::instance()->icon( RESPATH "images/inbox.svg" );
}
int
InboxItem::peerSortValue() const
{
return m_sortValue;
}
void
InboxItem::setSortValue( int value )
{
m_sortValue = value;
}
int
InboxItem::unlistenedCount() const
{
return ViewManager::instance()->inboxModel()->unlistenedCount();
}
void
InboxItem::activate()
{
Tomahawk::ViewPage* page = ViewManager::instance()->showInboxPage();
model()->linkSourceItemToPage( this, page );
}

View File

@ -0,0 +1,46 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk 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 3 of the License, or
* (at your option) any later version.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INBOXITEM_H
#define INBOXITEM_H
#include "SourceTreeItem.h"
class InboxItem : public SourceTreeItem
{
Q_OBJECT
public:
explicit InboxItem( SourcesModel* model, SourceTreeItem* parent );
virtual ~InboxItem();
virtual QString text() const;
virtual QIcon icon() const;
virtual int peerSortValue() const;
void setSortValue( int value );
int unlistenedCount() const;
public slots:
virtual void activate();
private:
int m_sortValue;
};
#endif // INBOXITEM_H