diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2eaef5604..6ca16f8b6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/libtomahawk/playlist/InboxModel.cpp b/src/libtomahawk/playlist/InboxModel.cpp index 8d3edf0fd..339e3e517 100644 --- a/src/libtomahawk/playlist/InboxModel.cpp +++ b/src/libtomahawk/playlist/InboxModel.cpp @@ -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 InboxModel::mergeSocialActions( QList first, QList second) { diff --git a/src/libtomahawk/playlist/InboxModel.h b/src/libtomahawk/playlist/InboxModel.h index 46284f49d..7e50b52f5 100644 --- a/src/libtomahawk/playlist/InboxModel.h +++ b/src/libtomahawk/playlist/InboxModel.h @@ -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. diff --git a/src/sourcetree/SourceDelegate.cpp b/src/sourcetree/SourceDelegate.cpp index 3483a6048..37d9a66b7 100644 --- a/src/sourcetree/SourceDelegate.cpp +++ b/src/sourcetree/SourceDelegate.cpp @@ -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 ); diff --git a/src/sourcetree/SourcesModel.cpp b/src/sourcetree/SourcesModel.cpp index e5a5e9b9b..dd20740ce 100644 --- a/src/sourcetree/SourcesModel.cpp +++ b/src/sourcetree/SourcesModel.cpp @@ -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 ); diff --git a/src/sourcetree/SourcesModel.h b/src/sourcetree/SourcesModel.h index 37e6a43c3..deff172b3 100644 --- a/src/sourcetree/SourcesModel.h +++ b/src/sourcetree/SourcesModel.h @@ -63,7 +63,8 @@ public: TemporaryPage = 7, LovedTracksPage = 10, - ScriptCollection = 11 + ScriptCollection = 11, + Inbox = 12 }; enum CategoryType { diff --git a/src/sourcetree/items/InboxItem.cpp b/src/sourcetree/items/InboxItem.cpp new file mode 100644 index 000000000..652d5a97f --- /dev/null +++ b/src/sourcetree/items/InboxItem.cpp @@ -0,0 +1,81 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + + +#include "InboxItem.h" + +#include "utils/ImageRegistry.h" +#include "ViewManager.h" +#include "ViewPage.h" +#include "playlist/InboxModel.h" + +#include +#include + + +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 ); +} diff --git a/src/sourcetree/items/InboxItem.h b/src/sourcetree/items/InboxItem.h new file mode 100644 index 000000000..81efa6e12 --- /dev/null +++ b/src/sourcetree/items/InboxItem.h @@ -0,0 +1,46 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + + +#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