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

Set the timer with track duration calculated in

This commit is contained in:
Leo Franchi
2011-11-16 22:32:47 -05:00
parent 3bf6682fce
commit 9aaadad95b
7 changed files with 18 additions and 11 deletions

View File

@@ -36,8 +36,8 @@ using namespace Tomahawk;
void void
DatabaseCommand_LogPlayback::postCommitHook() DatabaseCommand_LogPlayback::postCommitHook()
{ {
connect( this, SIGNAL( trackPlaying( Tomahawk::query_ptr ) ), connect( this, SIGNAL( trackPlaying( Tomahawk::query_ptr, unsigned int ) ),
source().data(), SLOT( onPlaybackStarted( Tomahawk::query_ptr ) ), Qt::QueuedConnection ); source().data(), SLOT( onPlaybackStarted( Tomahawk::query_ptr, unsigned int ) ), Qt::QueuedConnection );
connect( this, SIGNAL( trackPlayed( Tomahawk::query_ptr ) ), connect( this, SIGNAL( trackPlayed( Tomahawk::query_ptr ) ),
source().data(), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ), Qt::QueuedConnection ); source().data(), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ), Qt::QueuedConnection );
@@ -60,7 +60,7 @@ DatabaseCommand_LogPlayback::postCommitHook()
// if the play time is more than 10 minutes in the past, ignore // if the play time is more than 10 minutes in the past, ignore
else if ( m_action == Started && QDateTime::fromTime_t( playtime() ).secsTo( QDateTime::currentDateTime() ) < STARTED_THRESHOLD ) else if ( m_action == Started && QDateTime::fromTime_t( playtime() ).secsTo( QDateTime::currentDateTime() ) < STARTED_THRESHOLD )
{ {
emit trackPlaying( q ); emit trackPlaying( q, m_trackDuration );
} }
if ( source()->isLocal() ) if ( source()->isLocal() )

View File

@@ -37,6 +37,7 @@ Q_PROPERTY( QString artist READ artist WRITE setArtist )
Q_PROPERTY( QString track READ track WRITE setTrack ) Q_PROPERTY( QString track READ track WRITE setTrack )
Q_PROPERTY( unsigned int playtime READ playtime WRITE setPlaytime ) Q_PROPERTY( unsigned int playtime READ playtime WRITE setPlaytime )
Q_PROPERTY( unsigned int secsPlayed READ secsPlayed WRITE setSecsPlayed ) Q_PROPERTY( unsigned int secsPlayed READ secsPlayed WRITE setSecsPlayed )
Q_PROPERTY( unsigned int trackDuration READ trackDuration WRITE setTrackDuration )
Q_PROPERTY( int action READ action WRITE setAction ) Q_PROPERTY( int action READ action WRITE setAction )
public: public:
@@ -47,13 +48,14 @@ public:
}; };
explicit DatabaseCommand_LogPlayback( QObject* parent = 0 ) explicit DatabaseCommand_LogPlayback( QObject* parent = 0 )
: DatabaseCommandLoggable( parent ) : DatabaseCommandLoggable( parent ), m_playtime( 0 ), m_secsPlayed( 0 ), m_trackDuration( 0 )
{} {}
explicit DatabaseCommand_LogPlayback( const Tomahawk::result_ptr& result, Action action, unsigned int secsPlayed = 0, QObject* parent = 0 ) explicit DatabaseCommand_LogPlayback( const Tomahawk::result_ptr& result, Action action, unsigned int secsPlayed = 0, QObject* parent = 0 )
: DatabaseCommandLoggable( parent ), m_result( result ), m_secsPlayed( secsPlayed ), m_action( action ) : DatabaseCommandLoggable( parent ), m_result( result ), m_secsPlayed( secsPlayed ), m_action( action )
{ {
m_playtime = QDateTime::currentDateTimeUtc().toTime_t(); m_playtime = QDateTime::currentDateTimeUtc().toTime_t();
m_trackDuration = result->duration();
setSource( SourceList::instance()->getLocal() ); setSource( SourceList::instance()->getLocal() );
setArtist( result->artist()->name() ); setArtist( result->artist()->name() );
@@ -82,11 +84,14 @@ public:
unsigned int secsPlayed() const { return m_secsPlayed; } unsigned int secsPlayed() const { return m_secsPlayed; }
void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; } void setSecsPlayed( unsigned int i ) { m_secsPlayed = i; }
unsigned int trackDuration() const { return m_trackDuration; }
void setTrackDuration( unsigned int trackDuration ) { m_trackDuration = trackDuration; }
int action() const { return m_action; } int action() const { return m_action; }
void setAction( int a ) { m_action = (Action)a; } void setAction( int a ) { m_action = (Action)a; }
signals: signals:
void trackPlaying( const Tomahawk::query_ptr& query ); void trackPlaying( const Tomahawk::query_ptr& query, unsigned int duration );
void trackPlayed( const Tomahawk::query_ptr& query ); void trackPlayed( const Tomahawk::query_ptr& query );
private: private:
@@ -96,6 +101,7 @@ private:
QString m_track; QString m_track;
unsigned int m_playtime; unsigned int m_playtime;
unsigned int m_secsPlayed; unsigned int m_secsPlayed;
unsigned int m_trackDuration;
Action m_action; Action m_action;
}; };

View File

@@ -266,6 +266,7 @@ CREATE TABLE IF NOT EXISTS playback_log (
playtime INTEGER NOT NULL, -- when playback finished (timestamp) playtime INTEGER NOT NULL, -- when playback finished (timestamp)
secs_played INTEGER NOT NULL secs_played INTEGER NOT NULL
); );
CREATE INDEX playback_log_source ON playback_log(source); CREATE INDEX playback_log_source ON playback_log(source);
CREATE INDEX playback_log_track ON playback_log(track); CREATE INDEX playback_log_track ON playback_log(track);

View File

@@ -1,5 +1,5 @@
/* /*
This file was automatically generated from schema.sql on Thu Sep 29 17:28:17 EDT 2011. This file was automatically generated from schema.sql on Wed Nov 16 22:47:16 EST 2011.
*/ */
static const char * tomahawk_schema_sql = static const char * tomahawk_schema_sql =

View File

@@ -59,7 +59,6 @@ Source::Source( int id, const QString& username )
m_online = true; m_online = true;
} }
m_currentTrackTimer.setInterval( 600000 ); // 10 minutes
m_currentTrackTimer.setSingleShot( true ); m_currentTrackTimer.setSingleShot( true );
connect( &m_currentTrackTimer, SIGNAL( timeout() ), this, SLOT( trackTimerFired() ) ); connect( &m_currentTrackTimer, SIGNAL( timeout() ), this, SLOT( trackTimerFired() ) );
} }
@@ -306,11 +305,12 @@ Source::getPlaylistInterface()
void void
Source::onPlaybackStarted( const Tomahawk::query_ptr& query ) Source::onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration )
{ {
qDebug() << Q_FUNC_INFO << query->toString(); qDebug() << Q_FUNC_INFO << query->toString();
m_currentTrack = query; m_currentTrack = query;
m_currentTrackTimer.stop(); m_currentTrackTimer.start( duration * 1000 + 900000 ); // duration comes in seconds
if ( m_playlistInterface.isNull() ) if ( m_playlistInterface.isNull() )
getPlaylistInterface(); getPlaylistInterface();
emit playbackStarted( query ); emit playbackStarted( query );

View File

@@ -122,7 +122,7 @@ private slots:
void onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info ); void onStateChanged( DBSyncConnection::State newstate, DBSyncConnection::State oldstate, const QString& info );
void onPlaybackStarted( const Tomahawk::query_ptr& query ); void onPlaybackStarted( const Tomahawk::query_ptr& query, unsigned int duration );
void onPlaybackFinished( const Tomahawk::query_ptr& query ); void onPlaybackFinished( const Tomahawk::query_ptr& query );
void trackTimerFired(); void trackTimerFired();

View File

@@ -667,7 +667,7 @@ void JabberPlugin::onPresenceReceived( const Jreen::RosterItem::Ptr &item, const
Jreen::Capabilities::Ptr caps = presence.payload<Jreen::Capabilities>(); Jreen::Capabilities::Ptr caps = presence.payload<Jreen::Capabilities>();
if( caps ) if( caps )
{ {
qDebug() << Q_FUNC_INFO << fulljid << "Running tomahawk: maybe" << "caps " << caps->node() << "requesting disco..."; // qDebug() << Q_FUNC_INFO << fulljid << "Running tomahawk: maybe" << "caps " << caps->node() << "requesting disco...";
// request disco features // request disco features
QString node = caps->node() + '#' + caps->ver(); QString node = caps->node() + '#' + caps->ver();