[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [amarok] src: Fix: improve handling of invalid last played time when playcount > 0
From:       Ralf Engels <ralf-engels () gmx ! de>
Date:       2015-02-01 20:48:15
Message-ID: E1YI1RH-00038C-Ib () scm ! kde ! org
[Download RAW message or body]

Git commit 89813bfd055a4fe8148e388c1b004f3773b33530 by Ralf Engels.
Committed on 01/02/2015 at 19:28.
Pushed by rengels into branch 'master'.

Fix: improve handling of invalid last played time when playcount > 0

Use Amarok::verboseTimeSince in TagDialog
Check for playcount > 0 in PlaylistModel

M  +2    -0    src/core/support/Amarok.cpp
M  +6    -9    src/dialogs/TagDialog.cpp
M  +4    -2    src/playlist/PlaylistModel.cpp

http://commits.kde.org/amarok/89813bfd055a4fe8148e388c1b004f3773b33530

diff --git a/src/core/support/Amarok.cpp b/src/core/support/Amarok.cpp
index ca59725..791cff0 100644
--- a/src/core/support/Amarok.cpp
+++ b/src/core/support/Amarok.cpp
@@ -40,6 +40,8 @@ QMutex Amarok::globalDirsMutex;
 namespace Amarok
 {
 
+    // TODO: sometimes we have a playcount but no valid datetime.
+    //   in such a case we should maybe display "Unknown" and not "Never"
     QString verboseTimeSince( const QDateTime &datetime )
     {
         if( datetime.isNull() || !datetime.toTime_t() )
diff --git a/src/dialogs/TagDialog.cpp b/src/dialogs/TagDialog.cpp
index 48aadd9..54e8957 100644
--- a/src/dialogs/TagDialog.cpp
+++ b/src/dialogs/TagDialog.cpp
@@ -779,17 +779,14 @@ TagDialog::setTagsToUi( const QVariantMap &tags )
     ui->qSpinBox_score->setValue( tags.value( Meta::Field::SCORE ).toInt() );
     ui->ratingWidget->setRating( tags.value( Meta::Field::RATING ).toInt() );
     ui->ratingWidget->setMaxRating( 10 );
-    ui->qLabel_playcount->setText( unknownSafe( tags.value( Meta::Field::PLAYCOUNT ).toInt() ) );
+    int playcount = tags.value( Meta::Field::PLAYCOUNT ).toInt();
+    ui->qLabel_playcount->setText( unknownSafe( playcount ) );
 
-    QDate firstPlayed = tags.value( Meta::Field::FIRST_PLAYED ).toDate();
-    ui->qLabel_firstPlayed->setText( firstPlayed.isValid() ?
-                                     KGlobal::locale()->formatDate( firstPlayed, KLocale::ShortDate ) :
-                                     i18nc( "When this track first played", "Never") );
+    QDateTime firstPlayed = tags.value( Meta::Field::FIRST_PLAYED ).toDateTime();
+    ui->qLabel_firstPlayed->setText( Amarok::verboseTimeSince( firstPlayed ) );
 
-    QDate lastPlayed = tags.value( Meta::Field::LAST_PLAYED ).toDate();
-    ui->qLabel_lastPlayed->setText( lastPlayed.isValid() ?
-                                    KGlobal::locale()->formatDate( lastPlayed, KLocale::ShortDate ) :
-                                    i18nc( "When this track was last played", "Never") );
+    QDateTime lastPlayed = tags.value( Meta::Field::LAST_PLAYED ).toDateTime();
+    ui->qLabel_lastPlayed->setText( Amarok::verboseTimeSince( lastPlayed ) );
 
     ui->qLabel_collection->setText( tags.contains( Meta::Field::COLLECTION ) ?
                                     tags.value( Meta::Field::COLLECTION ).toString() :
diff --git a/src/playlist/PlaylistModel.cpp b/src/playlist/PlaylistModel.cpp
index 32060ba..9d48dd5 100644
--- a/src/playlist/PlaylistModel.cpp
+++ b/src/playlist/PlaylistModel.cpp
@@ -495,10 +495,12 @@ Playlist::Model::data( const QModelIndex& index, int role ) const
             }
             case LastPlayed:
             {
-                if( statistics->lastPlayed().isValid() )
+                if( statistics->playCount() == 0 )
+                    return i18nc( "The amount of time since last played", "Never" );
+                else if( statistics->lastPlayed().isValid() )
                     return Amarok::verboseTimeSince( statistics->lastPlayed() );
                 else
-                    return i18nc( "The amount of time since last played", "Never" );
+                    return i18nc( "When this track was last played", "Unknown" );
             }
             case Length:
             {

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic