diff --git a/include/tomahawk/result.h b/include/tomahawk/result.h index fa826d720..792e8e411 100644 --- a/include/tomahawk/result.h +++ b/include/tomahawk/result.h @@ -4,7 +4,6 @@ #include #include "collection.h" -#include "source.h" #include "tomahawk/typedefs.h" namespace Tomahawk @@ -32,11 +31,12 @@ public: unsigned int bitrate() const { return m_bitrate; } unsigned int size() const { return m_size; } unsigned int albumpos() const { return m_albumpos; } + unsigned int modificationTime() const { return m_modtime; } // for debug output: QString toString() const { - return QString( "Result(%1 %2\t%3 - %4 %5" ).arg( id() ).arg( score() ).arg( artist() ).arg( track() ).arg( url() ); + return QString( "Result(%1 %2\t%3 - %4 %5" ).arg( id() ).arg( score() ).arg( artist() ).arg( track() ).arg( url() ); } signals: @@ -53,10 +53,12 @@ private: QString m_track; QString m_url; QString m_mimetype; + unsigned int m_duration; unsigned int m_bitrate; unsigned int m_size; unsigned int m_albumpos; + unsigned int m_modtime; }; }; //ns diff --git a/src/database/databasecommand_alltracks.cpp b/src/database/databasecommand_alltracks.cpp index 8b663729b..073a2ab31 100644 --- a/src/database/databasecommand_alltracks.cpp +++ b/src/database/databasecommand_alltracks.cpp @@ -48,7 +48,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) t["size"] = query.value( 4 ).toInt(); t["duration"] = query.value( 5 ).toInt(); t["bitrate"] = query.value( 6 ).toInt(); - t["lastmodified"] = query.value( 9 ).toInt(); + t["mtime"] = query.value( 9 ).toInt(); t["mimetype"] = query.value( 10 ).toString(); t["albumpos"] = query.value( 11 ).toUInt(); tl.append( t ); diff --git a/src/playlist/collectionproxymodel.cpp b/src/playlist/collectionproxymodel.cpp index b00ef3d3a..c63102148 100644 --- a/src/playlist/collectionproxymodel.cpp +++ b/src/playlist/collectionproxymodel.cpp @@ -40,6 +40,7 @@ CollectionProxyModel::lessThan( const QModelIndex& left, const QModelIndex& righ QString track2 = q2->track(); unsigned int albumpos1 = 0, albumpos2 = 0; unsigned int bitrate1 = 0, bitrate2 = 0; + unsigned int mtime1 = 0, mtime2 = 0; if ( q1->numResults() ) { @@ -49,6 +50,7 @@ CollectionProxyModel::lessThan( const QModelIndex& left, const QModelIndex& righ track1 = r->track(); albumpos1 = r->albumpos(); bitrate1 = r->bitrate(); + mtime1 = r->modificationTime(); } if ( q2->numResults() ) { @@ -58,6 +60,7 @@ CollectionProxyModel::lessThan( const QModelIndex& left, const QModelIndex& righ track2 = r->track(); albumpos2 = r->albumpos(); bitrate2 = r->bitrate(); + mtime2 = r->modificationTime(); } if ( left.column() == 0 ) // sort by artist @@ -92,6 +95,10 @@ CollectionProxyModel::lessThan( const QModelIndex& left, const QModelIndex& righ { return bitrate1 < bitrate2; } + else if ( left.column() == 5 ) // sort by mtime + { + return mtime1 < mtime2; + } return QString::localeAwareCompare( sourceModel()->data( left ).toString(), sourceModel()->data( right ).toString() ) < 0; diff --git a/src/playlist/trackmodel.cpp b/src/playlist/trackmodel.cpp index 67a5a32ea..84640f303 100644 --- a/src/playlist/trackmodel.cpp +++ b/src/playlist/trackmodel.cpp @@ -55,7 +55,7 @@ TrackModel::rowCount( const QModelIndex& parent ) const int TrackModel::columnCount( const QModelIndex& parent ) const { - return 6; + return 7; } @@ -160,6 +160,10 @@ TrackModel::data( const QModelIndex& index, int role ) const break; case 5: + return TomahawkUtils::ageToString( QDateTime::fromTime_t( query->results().first()->modificationTime() ) ); + break; + + case 6: return query->results().first()->collection()->source()->friendlyName(); break; } @@ -173,7 +177,7 @@ QVariant TrackModel::headerData( int section, Qt::Orientation orientation, int role ) const { QStringList headers; - headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Origin" ); + headers << tr( "Artist" ) << tr( "Track" ) << tr( "Album" ) << tr( "Duration" ) << tr( "Bitrate" ) << tr( "Last Modified" ) << tr( "Origin" ); if ( orientation == Qt::Horizontal && role == Qt::DisplayRole && section >= 0 ) { return headers.at( section ); diff --git a/src/playlist/trackview.cpp b/src/playlist/trackview.cpp index 2f822e5f5..44b866218 100644 --- a/src/playlist/trackview.cpp +++ b/src/playlist/trackview.cpp @@ -83,9 +83,9 @@ TrackView::restoreColumnsState() TomahawkSettings* s = APP->settings(); QList list = s->playlistColumnSizes(); - if ( list.count() != 6 ) // FIXME: const + if ( list.count() != 7 ) // FIXME: const { - m_columnWeights << 0.22 << 0.29 << 0.19 << 0.08 << 0.08 << 0.14; + m_columnWeights << 0.19 << 0.25 << 0.18 << 0.07 << 0.07 << 0.10 << 0.14; } else { diff --git a/src/result.cpp b/src/result.cpp index 88021446f..fd524824c 100644 --- a/src/result.cpp +++ b/src/result.cpp @@ -19,6 +19,7 @@ Result::Result( const QVariant& v, const collection_ptr& collection ) m_bitrate = m.value( "bitrate" ).toUInt(); m_size = m.value( "size" ).toUInt(); m_albumpos = m.value( "albumpos" ).toUInt(); + m_modtime = m.value( "mtime" ).toUInt(); if ( !m_collection.isNull() ) connect( m_collection->source().data(), SIGNAL( offline() ), SIGNAL( becomingUnavailable() ), Qt::QueuedConnection ); diff --git a/src/utils/tomahawkutils.cpp b/src/utils/tomahawkutils.cpp index c3f8e2538..b7b6b494c 100644 --- a/src/utils/tomahawkutils.cpp +++ b/src/utils/tomahawkutils.cpp @@ -1,7 +1,9 @@ #include "tomahawkutils.h" #include +#include #include +#include #ifdef WIN32 #include @@ -126,4 +128,67 @@ timeToString( int seconds ) .arg( secs < 10 ? "0" + QString::number( secs ) : QString::number( secs ) ); } +QString +ageToString( const QDateTime& time ) +{ + QDateTime now = QDateTime::currentDateTime(); + + int mins = time.secsTo( now ) / 60; + int hours = mins / 60; + int days = time.daysTo( now ); + int weeks = days / 7; + int months = days / 30.42; + int years = months / 12; + + if ( years ) + { + if ( years > 1 ) + return QString( "%1 years ago" ).arg( years ); + else + return QString( "%1 year ago" ).arg( years ); + } + + if ( months ) + { + if ( months > 1 ) + return QString( "%1 months ago" ).arg( months ); + else + return QString( "%1 month ago" ).arg( months ); + } + + if ( weeks ) + { + if ( weeks > 1 ) + return QString( "%1 weeks ago" ).arg( weeks ); + else + return QString( "%1 week ago" ).arg( weeks ); + } + + if ( days ) + { + if ( days > 1 ) + return QString( "%1 days ago" ).arg( days ); + else + return QString( "%1 day ago" ).arg( days ); + } + + if ( hours ) + { + if ( hours > 1 ) + return QString( "%1 hours ago" ).arg( hours ); + else + return QString( "%1 hour ago" ).arg( hours ); + } + + if ( mins ) + { + if ( mins > 1 ) + return QString( "%1 minutes ago" ).arg( mins ); + else + return QString( "%1 minute ago" ).arg( mins ); + } + + return QString(); +} + } // ns diff --git a/src/utils/tomahawkutils.h b/src/utils/tomahawkutils.h index b7b77821e..f4919254a 100644 --- a/src/utils/tomahawkutils.h +++ b/src/utils/tomahawkutils.h @@ -1,7 +1,9 @@ #ifndef TOMAHAWKUTILS_H #define TOMAHAWKUTILS_H -#include +class QDir; +class QDateTime; +class QString; namespace TomahawkUtils { @@ -9,6 +11,7 @@ namespace TomahawkUtils QDir appDataDir(); QString timeToString( int seconds ); + QString ageToString( const QDateTime& time ); } #endif // TOMAHAWKUTILS_H