diff -urN amarok-2.3.1/src/TrayIcon.cpp amarok-2.3.1-new//src/TrayIcon.cpp --- amarok-2.3.1/src/TrayIcon.cpp 2010-05-27 18:37:20.000000000 +0000 +++ amarok-2.3.1-new//src/TrayIcon.cpp 2010-07-11 15:21:36.000000000 +0000 @@ -26,33 +26,24 @@ #include "EngineController.h" #include "amarokconfig.h" #include "GlobalCurrentTrackActions.h" -#include "core/meta/support/MetaConstants.h" #include "core/capabilities/CurrentTrackActionsCapability.h" #include "playlist/PlaylistActions.h" -#include "playlist/PlaylistModelStack.h" #include "SvgHandler.h" #include #include #include -#include -#include #include #include #include #include -#include #include -#include -#include #include -#include #include Amarok::TrayIcon::TrayIcon( QObject *parent ) : KStatusNotifierItem( parent ) , Engine::EngineObserver( The::engineController() ) - , m_trackLength( 0 ) , m_separator( 0 ) { DEBUG_BLOCK @@ -64,13 +55,13 @@ PERF_LOG( "Before adding actions" ); - #ifdef Q_WS_MAC +#ifdef Q_WS_MAC // Add these functions to the dock icon menu in OS X extern void qt_mac_set_dock_menu(QMenu *); qt_mac_set_dock_menu( contextMenu() ); contextMenu()->addAction( ac->action( "playlist_playmedia" ) ); contextMenu()->addSeparator(); - #endif +#endif contextMenu()->addAction( ac->action( "prev" ) ); contextMenu()->addAction( ac->action( "play_pause" ) ); @@ -79,105 +70,87 @@ contextMenu()->setObjectName( "TrayIconContextMenu" ); PERF_LOG( "Adding system tray icon" ); - paintIcon(); - setupToolTip(); + setIconByName( "amarok" ); + + setupToolTip( true ); connect( this, SIGNAL( scrollRequested( int, Qt::Orientation ) ), SLOT( slotScrollRequested(int, Qt::Orientation) ) ); connect( this, SIGNAL( secondaryActivateRequested( const QPoint & ) ), SLOT( slotActivated() ) ); } void -Amarok::TrayIcon::setupToolTip() +Amarok::TrayIcon::setupToolTip( bool updateIcon ) { if( m_track ) { setToolTipTitle( The::engineController()->prettyNowPlaying() ); - QStringList tooltip; - // TODO: Use Observer to get notified about changed album art - if( m_track->album() ) + // check if we really need to update the icon (performance tweak) + if( updateIcon ) { - const QString uid = m_track->uidUrl(); - if ( uid != m_toolTipIconUid ) { - const QPixmap image = The::svgHandler()->imageWithBorder( m_track->album(), KIconLoader::SizeLarge, 5 ); - if ( image.isNull() ) - { - setToolTipIconByName( "amarok" ); - m_toolTipIconUid.clear(); - } - else - { - setToolTipIconByPixmap( image ); - m_toolTipIconUid = uid; - } + if( m_track->album() && m_track->album()->hasImage() ) + { + QPixmap image = The::svgHandler()->imageWithBorder( m_track->album(), KIconLoader::SizeLarge, 5 ); + setToolTipIconByPixmap( image ); + } + else + { + setToolTipIconByName( "amarok" ); } - } - else - { - setToolTipIconByName( "amarok" ); - m_toolTipIconUid.clear(); } - QStringList left, right; + QStringList tooltip; - // TODO: Replace block by some other useful information QString volume; if ( The::engineController()->isMuted() ) + { volume = i18n( "Muted" ); + } else + { volume = QString( "%1%" ).arg( The::engineController()->volume() ); - right << QString("%1").arg( volume ); - left << QString( "%1" ).arg( i18n( "Volume" ) ); + } + tooltip << QString("%1: %2").arg( i18n( "Volume" ) ).arg( volume ); const float score = m_track->score(); if( score > 0.f ) { - right << QString::number( score, 'f', 2 ); // 2 digits after decimal point - left << i18n( "Score" ); + tooltip << QString( "%1: %2" ).arg( i18n( "Score" ) ).arg( QString::number( score, 'f', 2 ) ); } const int rating = m_track->rating(); if( rating > 0 ) { - QString s; + QString stars; for( int i = 0; i < rating / 2; ++i ) - s += QString( "" ) + stars += QString( "" ) .arg( KStandardDirs::locate( "data", "amarok/images/star.png" ) ) .arg( QFontMetrics( QToolTip::font() ).height() ) .arg( QFontMetrics( QToolTip::font() ).height() ); if( rating % 2 ) - s += QString( "" ) + stars += QString( "" ) .arg( KStandardDirs::locate( "data", "amarok/images/smallstar.png" ) ) .arg( QFontMetrics( QToolTip::font() ).height() ) .arg( QFontMetrics( QToolTip::font() ).height() ); - right << s; - left << i18n( "Rating" ); + + tooltip << QString( "%1: %2" ).arg( i18n( "Rating" ) ).arg( stars ); } const int count = m_track->playCount(); if( count > 0 ) { - right << QString::number( count ); - left << i18n( "Play Count" ); + tooltip << QString( "%1: %2" ).arg( i18n( "Play Count" ) ).arg( QString::number( count ) ); } const uint lastPlayed = m_track->lastPlayed(); - right << Amarok::verboseTimeSince( lastPlayed ); - left << i18n( "Last Played" ); - - // NOTE: It seems to be necessary to
each element indivdually - const QString row = "- %1: %2"; - for( int x = 0; x < left.count(); ++x ) - if ( !right[x].isEmpty() ) - tooltip << row.arg( left[x] ).arg( right[x] ); + tooltip << QString( "%1: %2" ).arg( i18n( "Last played" ) ).arg( Amarok::verboseTimeSince( lastPlayed ) ); setToolTipSubTitle( tooltip.join("
") ); } else { setToolTipIconByName( "amarok" ); - m_toolTipIconUid.clear(); setToolTipTitle( KCmdLineArgs::aboutData()->programName() ); setToolTipSubTitle( The::engineController()->prettyNowPlaying() ); } @@ -199,20 +172,26 @@ switch( state ) { case Phonon::PlayingState: - unsubscribeFrom( m_track ); + if ( m_track ) + { + unsubscribeFrom( m_track ); + unsubscribeFrom( m_track->album() ); + } m_track = track; - m_trackLength = m_track ? m_track->length() : 0; - subscribeTo( track ); + if ( track ) + { + subscribeTo( track ); + subscribeTo( track->album() ); + } - paintIcon( 0 ); + setOverlayIconByName( "media-playback-start" ); setupMenu(); break; case Phonon::StoppedState: m_track = 0; - m_trackLength = 0; - paintIcon(); + setOverlayIconByName( QString() ); setupMenu(); // remove custom track actions on stop break; @@ -223,21 +202,19 @@ case Phonon::LoadingState: case Phonon::ErrorState: case Phonon::BufferingState: + setOverlayIconByName( QString() ); break; } - setupToolTip(); + setupToolTip( true ); } void Amarok::TrayIcon::engineNewTrackPlaying() { m_track = The::engineController()->currentTrack(); - m_trackLength = m_track ? m_track->length() : 0; - - paintIcon( 0 ); - setupToolTip(); + setupToolTip( true ); setupMenu(); } @@ -246,17 +223,17 @@ { Q_UNUSED( track ) - setupToolTip(); + setupToolTip( false ); setupMenu(); } void -Amarok::TrayIcon::engineTrackPositionChanged( qint64 position, bool userSeek ) +Amarok::TrayIcon::metadataChanged( Meta::AlbumPtr album ) { - Q_UNUSED( userSeek ); + Q_UNUSED( album ) - if( m_trackLength ) - paintIcon( position ); + setupToolTip( true ); + setupMenu(); } void @@ -264,7 +241,7 @@ { Q_UNUSED( percent ); - setupToolTip(); + setupToolTip( false ); } void @@ -272,72 +249,7 @@ { Q_UNUSED( mute ); - setupToolTip(); -} - -void -Amarok::TrayIcon::paletteChange( const QPalette & op ) -{ - Q_UNUSED( op ); - - paintIcon(); -} - -void -Amarok::TrayIcon::paintIcon( qint64 trackPosition ) -{ - static qint64 oldMergePos = -1; - - // start up - // TODO: Move these two blocks to ctor (warning: might get some regressions) - if( m_baseIcon.isNull() ) - { - m_baseIcon = KIconLoader::global()->loadIcon( "amarok", KIconLoader::Panel ); - setIconByPixmap( m_baseIcon ); // show icon - setOverlayIconByName( QString() ); - return; // HACK: return because m_baseIcon is still null after first startup (why?) - } - - if( m_grayedIcon.isNull() ) - { - m_grayedIcon = m_baseIcon; // copies object - KIconEffect::semiTransparent( m_grayedIcon ); - } - - // trackPosition < 0 means reset - if( trackPosition < 0 ) - { - oldMergePos = -1; - setIconByPixmap( m_baseIcon ); - setOverlayIconByName( QString() ); - return; - } - - // check if we are playing a stream - if( !m_trackLength ) - { - m_icon = m_baseIcon; - setIconByPixmap( m_icon ); - setOverlayIconByName( "media-playback-start" ); - return; - } - - const qint64 mergePos = ( float( trackPosition ) / m_trackLength ) * m_icon.height(); - - // return if pixmap would stay the same - if( oldMergePos == mergePos ) - return; - - // draw m_baseIcon on top of the gray version - m_icon = m_grayedIcon; // copies object - QPainter p( &m_icon ); - p.drawPixmap( 0, 0, m_baseIcon, 0, 0, 0, m_icon.height() - mergePos ); - p.end(); - - oldMergePos = mergePos; - - setIconByPixmap( m_icon ); - setOverlayIconByName( "media-playback-start" ); + setupToolTip( false ); } void diff -urN amarok-2.3.1/src/TrayIcon.h amarok-2.3.1-new//src/TrayIcon.h --- amarok-2.3.1/src/TrayIcon.h 2010-05-27 18:37:20.000000000 +0000 +++ amarok-2.3.1-new//src/TrayIcon.h 2010-07-11 15:21:36.000000000 +0000 @@ -1,7 +1,7 @@ /**************************************************************************************** * Copyright (c) 2003 Stanislav Karchebny * - * Copyright (c) 2009 Kevin Funk * * Copyright (c) 2009 Mark Kretschmann * + * Copyright (c) 2009,2010 Kevin Funk * * * * This program is free software; you can redistribute it and/or modify it under * * the terms of the GNU General Public License as published by the Free Software * @@ -19,18 +19,15 @@ #ifndef AMAROK_TRAYICON_H #define AMAROK_TRAYICON_H -#include "core/engine/EngineObserver.h" //baseclass +#include "core/engine/EngineObserver.h" // baseclass #include "core/meta/Meta.h" #include "core/support/SmartPointerList.h" -#include //baseclass +#include // baseclass #include #include -class QEvent; -class App; - namespace Amarok { @@ -40,24 +37,20 @@ public: TrayIcon( QObject *parent ); - friend class ::App; - + void setVisible( bool visible ); protected: // reimplemented from engineobserver virtual void engineStateChanged( Phonon::State state, Phonon::State oldState = Phonon::StoppedState ); virtual void engineNewTrackPlaying(); - virtual void engineTrackPositionChanged( qint64 position, bool /*userSeek*/ ); virtual void engineVolumeChanged( int percent ); virtual void engineMuteStateChanged( bool mute ); - //Reimplemented from Meta::Observer + // reimplemented from Meta::Observer using Observer::metadataChanged; virtual void metadataChanged( Meta::TrackPtr track ); - - // get notified of 'highlight' color change - virtual void paletteChange( const QPalette & oldPalette ); + virtual void metadataChanged( Meta::AlbumPtr album ); private slots: void slotActivated(); @@ -65,15 +58,10 @@ private: void setupMenu(); - void setupToolTip(); - - void paintIcon( qint64 trackPosition = -1 ); + void setupToolTip( bool updateIcon ); Meta::TrackPtr m_track; - qint64 m_trackLength; - QString m_toolTipIconUid; - QPixmap m_baseIcon, m_grayedIcon, m_icon; SmartPointerList m_extraActions; QPointer m_separator; };