diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 7cb24f02f..92e0bd1e8 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -447,6 +447,7 @@ set( libHeaders widgets/SocialPlaylistWidget.h widgets/infowidgets/sourceinfowidget.h widgets/infowidgets/ArtistInfoWidget.h + widgets/infowidgets/ArtistInfoWidget_p.h widgets/infowidgets/AlbumInfoWidget.h widgets/Breadcrumb.h widgets/BreadcrumbButton.h diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index 975e2f605..0105e6b92 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -88,6 +88,12 @@ AlbumInfoWidget::~AlbumInfoWidget() delete ui; } +PlaylistInterface* +AlbumInfoWidget::playlistInterface() const +{ + return ui->tracksView->playlistInterface(); +} + void AlbumInfoWidget::onModeToggle() diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h index bb5c521d0..17e47f0d5 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.h @@ -64,7 +64,7 @@ public: void load( const Tomahawk::album_ptr& album ); virtual QWidget* widget() { return this; } - virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + virtual Tomahawk::PlaylistInterface* playlistInterface() const; virtual QString title() const { return m_title; } virtual QString description() const { return m_description; } diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp index 32a32b083..f57866878 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.cpp @@ -17,12 +17,14 @@ */ #include "ArtistInfoWidget.h" +#include "ArtistInfoWidget_p.h" #include "ui_ArtistInfoWidget.h" #include "audio/audioengine.h" #include "viewmanager.h" #include "playlist/treemodel.h" #include "playlist/playlistmodel.h" +#include "playlist/treeproxymodel.h" #include "database/databasecommand_alltracks.h" #include "database/databasecommand_allalbums.h" @@ -45,6 +47,8 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* { ui->setupUi( this ); + m_plInterface = new MetaPlaylistInterface( this ); + ui->albums->setFrameShape( QFrame::NoFrame ); ui->albums->setAttribute( Qt::WA_MacShowFocusRect, 0 ); ui->relatedArtists->setFrameShape( QFrame::NoFrame ); @@ -93,9 +97,16 @@ ArtistInfoWidget::ArtistInfoWidget( const Tomahawk::artist_ptr& artist, QWidget* ArtistInfoWidget::~ArtistInfoWidget() { + delete m_plInterface; delete ui; } +PlaylistInterface* +ArtistInfoWidget::playlistInterface() const +{ + return m_plInterface; +} + void ArtistInfoWidget::onModeToggle() diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h index 65ef84f29..754578bef 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget.h @@ -47,6 +47,8 @@ namespace Ui class ArtistInfoWidget; } +class MetaPlaylistInterface; + class DLLEXPORT ArtistInfoWidget : public QWidget, public Tomahawk::ViewPage { Q_OBJECT @@ -66,7 +68,7 @@ public: void load( const Tomahawk::artist_ptr& artist ); virtual QWidget* widget() { return this; } - virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + virtual Tomahawk::PlaylistInterface* playlistInterface() const; virtual QString title() const { return m_title; } virtual QString description() const { return m_description; } @@ -103,6 +105,7 @@ private: TreeModel* m_relatedModel; TreeModel* m_albumsModel; PlaylistModel* m_topHitsModel; + MetaPlaylistInterface* m_plInterface; OverlayButton* m_button; @@ -111,6 +114,8 @@ private: QString m_longDescription; QString m_infoId; QPixmap m_pixmap; + + friend class MetaPlaylistInterface; }; #endif // ARTISTINFOWIDGET_H diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h new file mode 100644 index 000000000..4a3b6b50a --- /dev/null +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h @@ -0,0 +1,106 @@ +/* === This file is part of Tomahawk Player - === + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef ARTISTINFOWIDGET_P_H +#define ARTISTINFOWIDGET_P_H + +#include "ArtistInfoWidget.h" +#include "ui_ArtistInfoWidget.h" +#include "playlistinterface.h" +#include "treeproxymodel.h" +#include "result.h" + +#include + +class MetaPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +{ + Q_OBJECT +public: + explicit MetaPlaylistInterface( ArtistInfoWidget* w ) + : PlaylistInterface( this ) + , m_w( w ) + { + connect( m_w->ui->albums->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); + connect( m_w->ui->relatedArtists->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); + connect( m_w->ui->topHits->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); + + connect( m_w->ui->albums->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ), + SLOT( anyShuffleChanged( bool ) ) ); + connect( m_w->ui->relatedArtists->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ), + SLOT( anyShuffleChanged( bool ) ) ); + connect( m_w->ui->topHits->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ), + SLOT( anyShuffleChanged( bool ) ) ); + } + virtual ~MetaPlaylistInterface() {} + + + // Any one is fine, we keep them all synched + virtual RepeatMode repeatMode() const { return m_w->ui->albums->proxyModel()->repeatMode(); } + + virtual bool shuffled() const { return m_w->ui->albums->proxyModel()->shuffled(); } + + // Do nothing + virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); } + virtual Tomahawk::result_ptr siblingItem( int ) { return Tomahawk::result_ptr(); } + virtual int trackCount() const { return 0; } + virtual QList< Tomahawk::query_ptr > tracks() { return QList< Tomahawk::query_ptr >(); } + virtual int unfilteredTrackCount() const { return 0; } + +public slots: + virtual void setRepeatMode( RepeatMode mode ) + { + m_w->ui->albums->proxyModel()->setRepeatMode( mode ); + m_w->ui->relatedArtists->proxyModel()->setRepeatMode( mode ); + m_w->ui->topHits->proxyModel()->setRepeatMode( mode ); + } + + virtual void setShuffled( bool enabled ) + { + m_w->ui->albums->proxyModel()->setShuffled( enabled ); + m_w->ui->relatedArtists->proxyModel()->setShuffled( enabled ); + m_w->ui->topHits->proxyModel()->setShuffled( enabled ); + } + +signals: + void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + void nextTrackReady(); + +private slots: + void anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ) + { + emit repeatModeChanged( mode ); + } + + void anyShuffleChanged( bool enabled ) + { + emit shuffleModeChanged( enabled ); + } + +private: + ArtistInfoWidget* m_w; + +}; + +#endif