Bug 205038

Summary: [PATCH] If album keyword is empty, show "unknown album" in context window
Product: [Applications] amarok Reporter: Mikael Lammentausta <mikael.lammentausta>
Component: Context View/Current TrackAssignee: Amarok Developers <amarok-bugs-dist>
Status: RESOLVED FIXED    
Severity: normal CC: kfunk, lfranchi, nsm.nikhil, simon.esneault, vianasw
Priority: NOR    
Version: 2.3-GIT   
Target Milestone: 2.4.0   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 2.4
Sentry Crash Report:
Attachments: Patch to show unknown album/artist as an inactive text field

Description Mikael Lammentausta 2009-08-25 04:19:25 UTC
Version:           2.2-GIT (using KDE 4.3.0)
OS:                Linux
Installed from:    Compiled From Sources

In revision 4b7de4d08988bdac4936370fa9c041bcb50dc02d, if the album info in the track metadata is empty, the "Now playing" context view just says "on album" followed by blank.

It would be nicer if it said instead, in slightly shaded color tone with maybe italic font, "unknown album" (or would look it up from last.fm or something and cached this to the database).

With other displayed data such as artist this could be applied as well.
Comment 1 Kevin Funk 2010-05-28 16:03:09 UTC
This is the case for all fields in the current track applet. We should fix this.
Comment 2 Nikhil Marathe 2010-09-12 09:22:52 UTC
I have a fix ready, but I'm not sure if we're in string freeze right now. I can commit once that is clarified
Comment 3 Nikhil Marathe 2010-09-18 17:05:39 UTC
Created attachment 51786 [details]
Patch to show unknown album/artist as an inactive text field
Comment 4 Myriam Schweingruber 2010-09-18 23:28:22 UTC
Nikhil, string freeze is over since version 2.3.2 has been tagged
Comment 5 Nikhil Marathe 2010-09-27 11:30:17 UTC
commit 68672153b8474cd66d49cb50e3180690d1f40b1f
Author: Nikhil Marathe <nsm.nikhil@gmail.com>
Date:   Mon Sep 27 15:04:01 2010 +0530

    Fixed bug 205038 for CurrentTrackInfo applet
    
    If the album/artist is empty, "Unknown Album/Artist"
    is displayed using the disabled palette.
    
    This patch does have code repetition due to the requirement
    to have various things like geometry information and more around
    which makes putting the unknown information checking into a
    seperate function unwieldy.
    
    BUG: 205038

diff --git a/ChangeLog b/ChangeLog
index 9a48538..2622a99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,6 +17,7 @@ VERSION NEXT
       pressing SHIFT while clicking the action will bypass trash.
 
   BUGFIXES:
+    * If album keyword is empty, show "unknown album" in context window (BR 205038)
     * Ampache wouldn't connect to servers placed in a subdirectory.
     * Fixed an initialization bug which affected all context applets.
     * Fix bug where users could drag applets around indiscriminately
diff --git a/src/context/applets/currenttrack/CurrentTrack.cpp b/src/context/applets/currenttrack/CurrentTrack.cpp
index 7c70890..e6526f5 100644
--- a/src/context/applets/currenttrack/CurrentTrack.cpp
+++ b/src/context/applets/currenttrack/CurrentTrack.cpp
@@ -275,13 +275,33 @@ void CurrentTrack::constraintsEvent( Plasma::Constraints constraints )
     m_title->setPos( artistPos.x(), artistPos.y() - lineSpacing );
 
     const QString title = m_currentInfo[ Meta::Field::TITLE ].toString();
-    const QString artist = m_currentInfo.contains( Meta::Field::ARTIST ) ? m_currentInfo[ Meta::Field::ARTIST ].toString() : QString();
-    const QString album = m_currentInfo.contains( Meta::Field::ALBUM ) ? m_currentInfo[ Meta::Field::ALBUM ].toString() : QString();
+    QString artist = m_currentInfo.contains( Meta::Field::ARTIST ) ? m_currentInfo[ Meta::Field::ARTIST ].toString() : QString();
+
+    if( artist.isNull() ) {
+        QBrush brush = KColorScheme( QPalette::Disabled ).foreground( KColorScheme::NormalText );
+        m_artist->setBrush( brush );
+        artist = i18n( "Unknown Artist" );
+    }
+    else {
+        QBrush brush = KColorScheme( QPalette::Active ).foreground( KColorScheme::NormalText );
+        m_artist->setBrush( brush );
+    }
+
+    QString album = m_currentInfo.contains( Meta::Field::ALBUM ) ? m_currentInfo[ Meta::Field::ALBUM ].toString() : QString();
+
+    if( album.isNull() ) {
+        QBrush brush = KColorScheme( QPalette::Disabled ).foreground( KColorScheme::NormalText );
+        m_album->setBrush( brush );
+        album = i18n( "Unknown Album" );
+    }
+    else {
+        QBrush brush = KColorScheme( QPalette::Active ).foreground( KColorScheme::NormalText );
+        m_album->setBrush( brush );
+    }
 
     m_title->setScrollingText( title, QRectF( m_title->pos().x(), textY, textWidth, 30 ) );
     m_artist->setScrollingText( artist, QRectF( artistPos.x(), textY, textWidth, 30 ) );
     m_album->setScrollingText( album, QRectF( albumPos.x(), textY, textWidth, 30 ) );
-
     if( !m_trackActions.isEmpty() )
     {
         QPointF iconPos = albumPos;
@@ -376,10 +396,34 @@ CurrentTrack::dataUpdated( const QString& name, const Plasma::DataEngine::Data&
     m_favoriteTracks.clear();
 
     m_currentInfo = data[ "current" ].toMap();
-    m_title->setScrollingText( m_currentInfo[ Meta::Field::TITLE ].toString(), textRect );
-    const QString artist = m_currentInfo.contains( Meta::Field::ARTIST ) ? m_currentInfo[ Meta::Field::ARTIST ].toString() : QString();
+
+    const QString title = m_currentInfo[ Meta::Field::TITLE ].toString();
+    QString artist = m_currentInfo.contains( Meta::Field::ARTIST ) ? m_currentInfo[ Meta::Field::ARTIST ].toString() : QString();
+
+    if( artist.isNull() ) {
+        QBrush brush = KColorScheme( QPalette::Disabled ).foreground( KColorScheme::NormalText );
+        m_artist->setBrush( brush );
+        artist = i18n( "Unknown Artist" );
+    }
+    else {
+        QBrush brush = KColorScheme( QPalette::Active ).foreground( KColorScheme::NormalText );
+        m_artist->setBrush( brush );
+    }
+
+    QString album = m_currentInfo.contains( Meta::Field::ALBUM ) ? m_currentInfo[ Meta::Field::ALBUM ].toString() : QString();
+
+    if( album.isNull() ) {
+        QBrush brush = KColorScheme( QPalette::Disabled ).foreground( KColorScheme::NormalText );
+        m_album->setBrush( brush );
+        album = i18n( "Unknown Album" );
+    }
+    else {
+        QBrush brush = KColorScheme( QPalette::Active ).foreground( KColorScheme::NormalText );
+        m_album->setBrush( brush );
+    }
+
+    m_title->setScrollingText( title, textRect );
     m_artist->setScrollingText( artist, textRect );
-    const QString album = m_currentInfo.contains( Meta::Field::ALBUM ) ? m_currentInfo[ Meta::Field::ALBUM ].toString() : QString();
     m_album->setScrollingText( album, textRect );
 
     m_rating = m_currentInfo[ Meta::Field::RATING ].toInt();