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

Add "Mark as Listened" to Inbox.

This commit is contained in:
Teo Mrnjavac 2013-05-28 17:56:06 +02:00
parent a81d13a91f
commit ed575aa033
10 changed files with 62 additions and 4 deletions

View File

@ -214,6 +214,9 @@ ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
addSeparator();
if ( m_supportedActions & ActionMarkListened )
m_sigmap->setMapping( addAction( tr( "Mark as &Listened" ) ), ActionMarkListened );
if ( m_supportedActions & ActionDelete )
m_sigmap->setMapping( addAction( queries.count() > 1 ? tr( "&Remove Items" ) : tr( "&Remove Item" ) ), ActionDelete );

View File

@ -49,7 +49,8 @@ public:
ActionAlbumPage = 67,
ActionEditMetadata = 128,
ActionPlaylist = 256,
ActionSend = 512
ActionSend = 512,
ActionMarkListened = 1024
};
explicit ContextMenu( QWidget* parent = 0 );

View File

@ -172,7 +172,7 @@ Track::startPlaying()
DatabaseCommand_LogPlayback::Started );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
markAsListened();
}
@ -183,7 +183,12 @@ Track::finishPlaying( int timeElapsed )
DatabaseCommand_LogPlayback::Finished,
timeElapsed );
Database::instance()->enqueue( QSharedPointer< DatabaseCommand >( cmd ) );
}
void
Track::markAsListened()
{
bool isUnlistened = false;
foreach ( Tomahawk::SocialAction action, allSocialActions() )
{

View File

@ -111,6 +111,7 @@ public:
void startPlaying();
void finishPlaying( int timeElapsed );
void markAsListened();
signals:
void coverChanged();

View File

@ -171,6 +171,20 @@ InboxModel::showNotification( InboxJobItem::Side side,
}
void
InboxModel::markAsListened( const QModelIndexList& indexes )
{
foreach ( QModelIndex index, indexes )
{
PlayableItem* item = itemFromIndex( index );
if ( item && !item->query().isNull() )
{
item->query()->queryTrack()->markAsListened();
}
}
}
void
InboxModel::loadTracks()
{

View File

@ -53,6 +53,8 @@ public slots:
const QString& dbid,
const Tomahawk::trackdata_ptr& track );
virtual void markAsListened( const QModelIndexList& indexes );
private slots:
void loadTracks();

View File

@ -20,6 +20,8 @@
#include "InboxView.h"
#include "InboxModel.h"
#include "PlayableProxyModel.h"
#include "ContextMenu.h"
#include "utils/Logger.h"
InboxView::InboxView(QWidget *parent) :
TrackView(parent)
@ -36,3 +38,28 @@ InboxView::deleteSelectedItems()
proxyModel()->removeIndexes( selectedIndexes() );
}
}
void
InboxView::onMenuTriggered( int action )
{
if ( action == Tomahawk::ContextMenu::ActionMarkListened )
{
tDebug() << Q_FUNC_INFO << "Mark as Listened";
InboxModel* inboxModel = qobject_cast< InboxModel* >( model() );
if ( inboxModel != 0 )
{
QModelIndexList sourceIndexes;
foreach ( const QModelIndex& index, selectedIndexes() )
{
if ( index.column() )
continue;
sourceIndexes << proxyModel()->mapToSource( index );
}
inboxModel->markAsListened( sourceIndexes );
}
}
else
TrackView::onMenuTriggered( action );
}

View File

@ -33,6 +33,8 @@ public slots:
* Reimplemented in order to ignore PlayableModel::isReadOnly()
*/
virtual void deleteSelectedItems();
virtual void onMenuTriggered( int action );
};
#endif // INBOXVIEW_H

View File

@ -34,6 +34,7 @@
#include "utils/Closure.h"
#include "utils/AnimatedSpinner.h"
#include "utils/Logger.h"
#include "InboxModel.h"
#include <QKeyEvent>
@ -45,7 +46,6 @@
using namespace Tomahawk;
TrackView::TrackView( QWidget* parent )
: QTreeView( parent )
, m_model( 0 )
@ -651,6 +651,9 @@ TrackView::onCustomContextMenu( const QPoint& pos )
if ( model() && !model()->isReadOnly() )
m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionDelete );
if ( model() && qobject_cast< InboxModel* >( model() ) )
m_contextMenu->setSupportedActions( m_contextMenu->supportedActions() | ContextMenu::ActionMarkListened
| ContextMenu::ActionDelete );
QList<query_ptr> queries;
foreach ( const QModelIndex& index, selectedIndexes() )

View File

@ -93,7 +93,7 @@ public slots:
virtual void deleteSelectedItems();
void playItem();
void onMenuTriggered( int action );
virtual void onMenuTriggered( int action );
void onViewChanged();
void onScrollTimeout();