mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
* Added modification time as a Playlist / Collection column.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
#include <QObject>
|
||||
|
||||
#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
|
||||
|
@@ -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 );
|
||||
|
@@ -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;
|
||||
|
@@ -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 );
|
||||
|
@@ -83,9 +83,9 @@ TrackView::restoreColumnsState()
|
||||
TomahawkSettings* s = APP->settings();
|
||||
QList<QVariant> 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
|
||||
{
|
||||
|
@@ -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 );
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#include "tomahawkutils.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
@@ -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
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#ifndef TOMAHAWKUTILS_H
|
||||
#define TOMAHAWKUTILS_H
|
||||
|
||||
#include <QDir>
|
||||
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
|
||||
|
Reference in New Issue
Block a user