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

* Show when a track was played in the recently played tracks history.

This commit is contained in:
Christian Muehlhaeuser 2011-06-25 04:12:16 +02:00
parent 0685754481
commit 8e99dbf01e
7 changed files with 42 additions and 26 deletions

View File

@ -40,7 +40,7 @@ DatabaseCommand_LogPlayback::postCommitHook()
// do not auto resolve this track
Tomahawk::query_ptr q = Tomahawk::Query::get( m_artist, m_track, QString() );
q->setPlayedBy( source() );
q->setPlayedBy( source(), m_playtime );
if ( m_action == Finished )
{

View File

@ -67,11 +67,11 @@ DatabaseCommand_PlaybackHistory::exec( DatabaseImpl* dbi )
if ( query.value( 3 ).toUInt() == 0 )
{
q->setPlayedBy( SourceList::instance()->getLocal() );
q->setPlayedBy( SourceList::instance()->getLocal(), query.value( 1 ).toUInt() );
}
else
{
q->setPlayedBy( SourceList::instance()->get( query.value( 3 ).toUInt() ) );
q->setPlayedBy( SourceList::instance()->get( query.value( 3 ).toUInt() ), query.value( 1 ).toUInt() );
}
ql << q;

View File

@ -37,6 +37,8 @@
#define PLAYING_ICON QString( RESPATH "images/now-playing-speaker.png" )
using namespace Tomahawk;
PlaylistItemDelegate::PlaylistItemDelegate( TrackView* parent, TrackProxyModel* proxy )
: QStyledItemDelegate( (QObject*)parent )
@ -147,6 +149,8 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
QPixmap pixmap;
QString artist, track, upperText, lowerText;
source_ptr source = item->query()->playedBy().first;
if ( item->query()->results().count() )
{
artist = item->query()->results().first()->artist()->name();
@ -158,7 +162,7 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
track = item->query()->track();
}
if ( item->query()->playedBy().isNull() )
if ( source.isNull() )
{
upperText = artist;
lowerText = track;
@ -166,13 +170,14 @@ PlaylistItemDelegate::paintShort( QPainter* painter, const QStyleOptionViewItem&
else
{
upperText = QString( "%1 - %2" ).arg( artist ).arg( track );
QString playtime = TomahawkUtils::ageToString( QDateTime::fromTime_t( item->query()->playedBy().second ) );
if ( item->query()->playedBy() == SourceList::instance()->getLocal() )
lowerText = QString( "played by you" );
if ( source == SourceList::instance()->getLocal() )
lowerText = QString( "played %1 ago by you" ).arg( playtime );
else
lowerText = QString( "played by %1" ).arg( item->query()->playedBy()->friendlyName() );
lowerText = QString( "played %1 ago by %2" ).arg( playtime ).arg( source->friendlyName() );
pixmap = item->query()->playedBy()->avatar();
pixmap = source->avatar();
}
if ( pixmap.isNull() )

View File

@ -202,6 +202,14 @@ Query::id() const
}
void
Query::setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime )
{
m_playedBy.first = source;
m_playedBy.second = playtime;
}
bool
Query::resultSorter( const result_ptr& left, const result_ptr& right )
{

View File

@ -74,7 +74,7 @@ public:
bool isFullTextQuery() const { return !m_fullTextQuery.isEmpty(); }
bool resolvingFinished() const { return m_resolveFinished; }
Tomahawk::source_ptr playedBy() const { return m_playedBy; }
QPair< Tomahawk::source_ptr, unsigned int > playedBy() const { return m_playedBy; }
Tomahawk::Resolver* currentResolver() const;
QList< QWeakPointer< Tomahawk::Resolver > > resolvedBy() const { return m_resolvers; }
@ -94,7 +94,7 @@ public:
int duration() const { return m_duration; }
void setResolveFinished( bool resolved ) { m_resolveFinished = resolved; }
void setPlayedBy( const Tomahawk::source_ptr& source ) { m_playedBy = source; }
void setPlayedBy( const Tomahawk::source_ptr& source, unsigned int playtime );
signals:
void resultsAdded( const QList<Tomahawk::result_ptr>& );
@ -139,7 +139,7 @@ private:
int m_duration;
QString m_resultHint;
Tomahawk::source_ptr m_playedBy;
QPair< Tomahawk::source_ptr, unsigned int > m_playedBy;
QList< QWeakPointer< Tomahawk::Resolver > > m_resolvers;
mutable QMutex m_mutex;

View File

@ -91,7 +91,9 @@ Result::score() const
RID
Result::id() const
{
Q_ASSERT( !m_rid.isEmpty() );
if ( m_rid.isEmpty() )
m_rid = uuid();
return m_rid;
}

View File

@ -162,6 +162,7 @@ timeToString( int seconds )
.arg( secs < 10 ? "0" + QString::number( secs ) : QString::number( secs ) );
}
QString
ageToString( const QDateTime& time )
{
@ -177,49 +178,49 @@ ageToString( const QDateTime& time )
if ( years )
{
if ( years > 1 )
return QString( "%1 years" ).arg( years );
return QObject::tr( "%1 years" ).arg( years );
else
return QString( "%1 year" ).arg( years );
return QObject::tr( "%1 year" ).arg( years );
}
if ( months )
{
if ( months > 1 )
return QString( "%1 months" ).arg( months );
return QObject::tr( "%1 months" ).arg( months );
else
return QString( "%1 month" ).arg( months );
return QObject::tr( "%1 month" ).arg( months );
}
if ( weeks )
{
if ( weeks > 1 )
return QString( "%1 weeks" ).arg( weeks );
return QObject::tr( "%1 weeks" ).arg( weeks );
else
return QString( "%1 week" ).arg( weeks );
return QObject::tr( "%1 week" ).arg( weeks );
}
if ( days )
{
if ( days > 1 )
return QString( "%1 days" ).arg( days );
return QObject::tr( "%1 days" ).arg( days );
else
return QString( "%1 day" ).arg( days );
return QObject::tr( "%1 day" ).arg( days );
}
if ( hours )
{
if ( hours > 1 )
return QString( "%1 hours" ).arg( hours );
return QObject::tr( "%1 hours" ).arg( hours );
else
return QString( "%1 hour" ).arg( hours );
return QObject::tr( "%1 hour" ).arg( hours );
}
if ( mins )
{
if ( mins > 1 )
return QString( "%1 minutes" ).arg( mins );
return QObject::tr( "%1 minutes" ).arg( mins );
else
return QString( "%1 minute" ).arg( mins );
return QObject::tr( "%1 minute" ).arg( mins );
}
return QString();
@ -397,10 +398,10 @@ NetworkProxyFactory*
proxyFactory()
{
// Don't use this anywhere! It's provided here for access reasons, but QNAM deletes this at will!
if ( !s_proxyFactory )
s_proxyFactory = new NetworkProxyFactory();
return s_proxyFactory;
}