From efbbdf1e72e1953a837eebf40720b0fbb637d5cc Mon Sep 17 00:00:00 2001
From: Leo Franchi <lfranchi@kde.org>
Date: Thu, 22 Sep 2011 22:34:26 -0400
Subject: [PATCH] Show headphone icon as on for the local source if you are
 listening along to someone

---
 src/sourcetree/items/collectionitem.cpp |  4 ++--
 src/sourcetree/sourcedelegate.cpp       | 22 +++++++++++++---------
 2 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/sourcetree/items/collectionitem.cpp b/src/sourcetree/items/collectionitem.cpp
index 2ea070168..f50361182 100644
--- a/src/sourcetree/items/collectionitem.cpp
+++ b/src/sourcetree/items/collectionitem.cpp
@@ -203,7 +203,7 @@ CollectionItem::icon() const
 void
 CollectionItem::latchedOff( const source_ptr& from, const source_ptr& to )
 {
-    if ( from->isLocal() && m_source == to )
+    if ( from->isLocal() && ( m_source == to || m_source == from ) )
     {
         m_latchedOn = false;
         emit updated();
@@ -213,7 +213,7 @@ CollectionItem::latchedOff( const source_ptr& from, const source_ptr& to )
 void
 CollectionItem::latchedOn( const source_ptr& from, const source_ptr& to )
 {
-    if ( from->isLocal() && m_source == to )
+    if ( from->isLocal() && ( m_source == to || m_source == from ) )
     {
         m_latchedOn = true;
         emit updated();
diff --git a/src/sourcetree/sourcedelegate.cpp b/src/sourcetree/sourcedelegate.cpp
index 992e7f8c9..17d299f12 100644
--- a/src/sourcetree/sourcedelegate.cpp
+++ b/src/sourcetree/sourcedelegate.cpp
@@ -186,7 +186,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
 
         textRect = option.rect.adjusted( iconRect.width() + 8, painter->fontMetrics().height() + 6, -figWidth - 24, -4 );
         painter->setFont( normal );
-        if ( isPlaying )
+        if ( isPlaying || ( !colItem->source().isNull() && colItem->source()->isLocal() ) )
         {
             // Show a listen icon
             QPixmap pm;
@@ -194,15 +194,19 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co
             {
                 // Currently listening along
                 pm = m_headphonesOn;
-            } else {
+            } else if ( !colItem->source()->isLocal() ) {
                 pm = m_headphonesOff;
             }
-            QRect pmRect = textRect;
-            pmRect.setTop( pmRect.bottom() - painter->fontMetrics().height() );
-            pmRect.setRight( pmRect.left() + pmRect.height() );
-//             tDebug() << "DOING HEADPHONES RECT:" << pmRect;
-            painter->drawPixmap( pmRect, pm.scaledToHeight( pmRect.height(), Qt::SmoothTransformation ) );
-            textRect.adjust( pmRect.width() + 3, 0, 0, 0 );
+
+            if ( !pm.isNull() )
+            {
+                QRect pmRect = textRect;
+                pmRect.setTop( pmRect.bottom() - painter->fontMetrics().height() - 3 );
+                pmRect.setRight( pmRect.left() + pmRect.height() );
+    //             tDebug() << "DOING HEADPHONES RECT:" << pmRect;
+                painter->drawPixmap( pmRect, pm.scaledToHeight( pmRect.height(), Qt::SmoothTransformation ) );
+                textRect.adjust( pmRect.width() + 3, 0, 0, 0 );
+            }
         }
         text = painter->fontMetrics().elidedText( desc, Qt::ElideRight, textRect.width() );
         QTextOption to( Qt::AlignBottom );
@@ -401,7 +405,7 @@ SourceDelegate::editorEvent ( QEvent* event, QAbstractItemModel* model, const QS
         {
             CollectionItem* colItem = qobject_cast< CollectionItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
             Q_ASSERT( colItem );
-            if ( !colItem->source().isNull() && !colItem->source()->currentTrack().isNull() )
+            if ( !colItem->source().isNull() && !colItem->source()->currentTrack().isNull() && !colItem->source()->isLocal() )
             {
                 QMouseEvent* ev = static_cast< QMouseEvent* >( event );