From 98d939a81b980508a09d7311233d1137d184aa58 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 21 Oct 2011 12:06:21 -0400 Subject: [PATCH] Show speaker icon for any playing playlist --- .../playlist/customplaylistview.cpp | 16 +++++++++- src/libtomahawk/playlist/customplaylistview.h | 3 ++ src/libtomahawk/viewpage.h | 1 + .../widgets/infowidgets/AlbumInfoWidget.cpp | 13 ++++++++ .../widgets/infowidgets/AlbumInfoWidget.h | 1 + .../widgets/infowidgets/ArtistInfoWidget.cpp | 31 +++++++++++++++++++ .../widgets/infowidgets/ArtistInfoWidget.h | 3 +- src/libtomahawk/widgets/welcomewidget.cpp | 7 +++++ src/libtomahawk/widgets/welcomewidget.h | 1 + src/libtomahawk/widgets/whatshotwidget.cpp | 29 ++++++++++++++++- src/libtomahawk/widgets/whatshotwidget.h | 4 +-- src/sourcetree/items/genericpageitems.cpp | 7 ++--- src/sourcetree/items/temporarypageitem.h | 2 ++ src/sourcetree/sourcedelegate.cpp | 1 + 14 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/playlist/customplaylistview.cpp b/src/libtomahawk/playlist/customplaylistview.cpp index 625bce3d4..218b6ffb4 100644 --- a/src/libtomahawk/playlist/customplaylistview.cpp +++ b/src/libtomahawk/playlist/customplaylistview.cpp @@ -22,7 +22,8 @@ #include "database/databasecommand_genericselect.h" #include "database/database.h" #include "utils/tomahawkutils.h" -#include +#include "sourcelist.h" +#include "audio/audioengine.h" using namespace Tomahawk; @@ -54,6 +55,19 @@ CustomPlaylistView::CustomPlaylistView( CustomPlaylistView::PlaylistType type, c CustomPlaylistView::~CustomPlaylistView() {} +bool +CustomPlaylistView::isBeingPlayed() const +{ + return AudioEngine::instance()->currentTrackPlaylist() == playlistInterface(); +} + +bool +CustomPlaylistView::jumpToCurrentTrack() +{ + return PlaylistView::jumpToCurrentTrack(); +} + + void CustomPlaylistView::generateTracks() { diff --git a/src/libtomahawk/playlist/customplaylistview.h b/src/libtomahawk/playlist/customplaylistview.h index 0ed8dba21..b7e0b659d 100644 --- a/src/libtomahawk/playlist/customplaylistview.h +++ b/src/libtomahawk/playlist/customplaylistview.h @@ -46,7 +46,10 @@ public: virtual QPixmap pixmap() const; virtual QString description() const; virtual QString longDescription() const; + virtual bool isTemporaryPage() const { return false; } + virtual bool isBeingPlayed() const; + virtual bool jumpToCurrentTrack(); private slots: void tracksGenerated( QList tracks ); diff --git a/src/libtomahawk/viewpage.h b/src/libtomahawk/viewpage.h index 4cf5f0a61..6e32bcef9 100644 --- a/src/libtomahawk/viewpage.h +++ b/src/libtomahawk/viewpage.h @@ -53,6 +53,7 @@ public: virtual bool jumpToCurrentTrack() = 0; virtual bool isTemporaryPage() const { return false; } + virtual bool isBeingPlayed() const { return false; } virtual bool canAutoUpdate() const { return false; } virtual void setAutoUpdate( bool ) {} diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index f4250afd6..975e2f605 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -19,6 +19,7 @@ #include "AlbumInfoWidget.h" #include "ui_AlbumInfoWidget.h" +#include "audio/audioengine.h" #include "viewmanager.h" #include "database/database.h" #include "playlist/treemodel.h" @@ -117,6 +118,18 @@ AlbumInfoWidget::onLoadingFinished() m_button->show(); } +bool +AlbumInfoWidget::isBeingPlayed() const +{ + if ( ui->albumsView->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + if ( ui->tracksView->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + return false; +} + void AlbumInfoWidget::load( const album_ptr& album ) diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index ca1bc8130..bb5c521d0 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -75,6 +75,7 @@ public: virtual bool showStatsBar() const { return false; } virtual bool jumpToCurrentTrack() { return false; } + virtual bool isBeingPlayed() const; signals: void longDescriptionChanged( const QString& description ); diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 553d93680..f60f94acb 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -19,6 +19,7 @@ #include "ArtistInfoWidget.h" #include "ui_ArtistInfoWidget.h" +#include "audio/audioengine.h" #include "viewmanager.h" #include "playlist/treemodel.h" #include "playlist/playlistmodel.h" @@ -125,6 +126,36 @@ ArtistInfoWidget::onLoadingFinished() m_button->show(); } +bool +ArtistInfoWidget::isBeingPlayed() const +{ + if ( ui->albums->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + if ( ui->relatedArtists->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + if ( ui->topHits->playlistInterface() == AudioEngine::instance()->currentTrackPlaylist() ) + return true; + + return false; +} + +bool +ArtistInfoWidget::jumpToCurrentTrack() +{ + if ( ui->albums->jumpToCurrentTrack() ) + return true; + + if ( ui->relatedArtists->jumpToCurrentTrack() ) + return true; + + if ( ui->topHits->jumpToCurrentTrack() ) + return true; + + return false; +} + void ArtistInfoWidget::load( const artist_ptr& artist ) diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index 1f0a8a1d8..65ef84f29 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -76,7 +76,8 @@ public: virtual bool isTemporaryPage() const { return true; } virtual bool showStatsBar() const { return false; } - virtual bool jumpToCurrentTrack() { return false; } + virtual bool jumpToCurrentTrack(); + virtual bool isBeingPlayed() const; signals: void longDescriptionChanged( const QString& description ); diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index 0e7992967..804d14d16 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2011, Leo Franchi * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -98,6 +99,12 @@ WelcomeWidget::~WelcomeWidget() delete ui; } +bool +WelcomeWidget::isBeingPlayed() const +{ + return AudioEngine::instance()->currentTrackPlaylist() == ui->tracksView->playlistInterface(); +} + void WelcomeWidget::updateRecentTracks() diff --git a/src/libtomahawk/widgets/welcomewidget.h b/src/libtomahawk/widgets/welcomewidget.h index ccd8985e0..0dc92f040 100644 --- a/src/libtomahawk/widgets/welcomewidget.h +++ b/src/libtomahawk/widgets/welcomewidget.h @@ -93,6 +93,7 @@ public: virtual bool showInfoBar() const { return false; } virtual bool jumpToCurrentTrack() { return false; } + virtual bool isBeingPlayed() const; protected: void changeEvent( QEvent* e ); diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 3f2fb795c..89a113fa1 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2011, Leo Franchi * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +30,7 @@ #include "RecentPlaylistsModel.h" #include "audio/audioengine.h" +#include "dynamic/GeneratorInterface.h" #include "playlist/playlistmodel.h" #include "playlist/treeproxymodel.h" #include "widgets/overlaywidget.h" @@ -36,7 +38,6 @@ #include "widgets/kbreadcrumbselectionmodel.h" #include "utils/tomahawkutils.h" #include "utils/logger.h" -#include #include #define HISTORY_TRACK_ITEMS 25 @@ -99,6 +100,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( finished( QString ) ), SLOT( infoSystemFinished( QString ) ) ); + connect( AudioEngine::instance(), SIGNAL( playlistChanged( Tomahawk::PlaylistInterface* ) ), this, SLOT( playlistChanged( Tomahawk::PlaylistInterface* ) ) ); QTimer::singleShot( 0, this, SLOT( fetchData() ) ); } @@ -109,6 +111,31 @@ WhatsHotWidget::~WhatsHotWidget() } +bool +WhatsHotWidget::isBeingPlayed() const +{ + if ( AudioEngine::instance()->currentTrackPlaylist() == ui->artistsViewLeft->playlistInterface() ) + return true; + + if ( AudioEngine::instance()->currentTrackPlaylist() == ui->tracksViewLeft->playlistInterface() ) + return true; + + return false; +} + +bool +WhatsHotWidget::jumpToCurrentTrack() +{ + if ( ui->artistsViewLeft->jumpToCurrentTrack() ) + return true; + + if ( ui->tracksViewLeft->jumpToCurrentTrack() ) + return true; + + return false; +} + + void WhatsHotWidget::fetchData() { diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index 14286521e..e13c0421e 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -65,7 +65,8 @@ public: virtual bool showStatsBar() const { return false; } virtual bool showInfoBar() const { return false; } - virtual bool jumpToCurrentTrack() { return false; } + virtual bool jumpToCurrentTrack(); + virtual bool isBeingPlayed() const; protected: void changeEvent( QEvent* e ); @@ -80,7 +81,6 @@ private slots: void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemFinished( QString target ); void leftCrumbIndexChanged( QModelIndex ); - private: void setLeftViewArtists( TreeModel* artistModel ); void setLeftViewAlbums( AlbumModel* albumModel ); diff --git a/src/sourcetree/items/genericpageitems.cpp b/src/sourcetree/items/genericpageitems.cpp index d901fe4dc..eace899dc 100644 --- a/src/sourcetree/items/genericpageitems.cpp +++ b/src/sourcetree/items/genericpageitems.cpp @@ -85,9 +85,8 @@ GenericPageItem::setText( const QString &text ) bool GenericPageItem::isBeingPlayed() const { - if ( dynamic_cast< PlaylistInterface* >( m_get() ) ) - { - return AudioEngine::instance()->currentTrackPlaylist() == dynamic_cast< PlaylistInterface* >( m_get() ); - } + if ( m_get() ) + return m_get()->isBeingPlayed(); + return false; } diff --git a/src/sourcetree/items/temporarypageitem.h b/src/sourcetree/items/temporarypageitem.h index 28e5f4821..fe32d8a12 100644 --- a/src/sourcetree/items/temporarypageitem.h +++ b/src/sourcetree/items/temporarypageitem.h @@ -20,6 +20,7 @@ #define TEMPORARYPAGEITEM_H #include "items/sourcetreeitem.h" +#include "viewpage.h" class TemporaryPageItem : public SourceTreeItem { @@ -35,6 +36,7 @@ public: void removeFromList(); Tomahawk::ViewPage* page() const { return m_page; } + virtual bool isBeingPlayed() const { return m_page->isBeingPlayed(); } private: Tomahawk::ViewPage* m_page; diff --git a/src/sourcetree/sourcedelegate.cpp b/src/sourcetree/sourcedelegate.cpp index f24ba7080..99076ac92 100644 --- a/src/sourcetree/sourcedelegate.cpp +++ b/src/sourcetree/sourcedelegate.cpp @@ -140,6 +140,7 @@ SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, co const bool playable = ( type == SourcesModel::StaticPlaylist || type == SourcesModel::AutomaticPlaylist || type == SourcesModel::Station || + type == SourcesModel::TemporaryPage || type == SourcesModel::GenericPage ); if ( playable && item->isBeingPlayed() )