diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 80c931efe..7ac9c43dc 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -238,6 +238,7 @@ set( libGuiHeaders widgets/playlisttypeselectordlg.h widgets/welcomewidget.h widgets/whatshotwidget.h + widgets/whatshotwidget_p.h widgets/RecentlyPlayedPlaylistsModel.h widgets/RecentPlaylistsModel.h widgets/OverlayButton.h diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index 59ce86097..708a97a4a 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -369,6 +369,9 @@ ArtistView::onMenuTriggered( int action ) bool ArtistView::jumpToCurrentTrack() { + if ( !m_proxyModel ) + return false; + scrollTo( m_proxyModel->currentIndex(), QAbstractItemView::PositionAtCenter ); return true; } diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index dc2e59ef3..9dfae69e0 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -43,6 +43,15 @@ TreeProxyModel::TreeProxyModel( QObject* parent ) setSourceTreeModel( 0 ); } +QPersistentModelIndex +TreeProxyModel::currentIndex() const +{ + if ( !m_model ) + return QPersistentModelIndex(); + + return mapFromSource( m_model->currentItem() ); +} + void TreeProxyModel::setSourceModel( QAbstractItemModel* sourceModel ) diff --git a/src/libtomahawk/playlist/treeproxymodel.h b/src/libtomahawk/playlist/treeproxymodel.h index d15f3e8a8..84f09bcdb 100644 --- a/src/libtomahawk/playlist/treeproxymodel.h +++ b/src/libtomahawk/playlist/treeproxymodel.h @@ -39,7 +39,7 @@ public: virtual void setSourceTreeModel( TreeModel* sourceModel ); virtual void setSourceModel( QAbstractItemModel* sourceModel ); - virtual QPersistentModelIndex currentIndex() const { return mapFromSource( m_model->currentItem() ); } + virtual QPersistentModelIndex currentIndex() const; virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } virtual QList tracks() { Q_ASSERT( FALSE ); QList queries; return queries; } diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 266e10e7e..5aa3fd46e 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -67,6 +67,10 @@ public: virtual void reset() {} + // Some playlist interfaces can wrap other interfaces. When checking for top-level + // equality (say, to compare the currently playing interface) this might be needed + virtual bool hasChildInterface( PlaylistInterface* ) { return false; } + QObject* object() const { return m_object; } static void dontDelete( Tomahawk::PlaylistInterface* obj ) diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index b7cd72b08..f7ea016c8 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -818,6 +818,8 @@ ViewManager::pageForInterface( Tomahawk::PlaylistInterface* interface ) const ViewPage* page = m_pageHistory.at( i ); if ( page->playlistInterface() == interface ) return page; + if ( page->playlistInterface() && page->playlistInterface()->hasChildInterface( interface ) ) + return page; } return 0; diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h index 4a3b6b50a..6a312b5e3 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h @@ -64,6 +64,12 @@ public: virtual QList< Tomahawk::query_ptr > tracks() { return QList< Tomahawk::query_ptr >(); } virtual int unfilteredTrackCount() const { return 0; } + virtual bool hasChildInterface( PlaylistInterface* other ) + { + return ( m_w->ui->albums->playlistInterface() == other ) || + ( m_w->ui->relatedArtists->playlistInterface() == other ) || + ( m_w->ui->topHits->playlistInterface() == other ); + } public slots: virtual void setRepeatMode( RepeatMode mode ) { diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index bbd47f6bf..4034f0b37 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -99,6 +99,19 @@ WelcomeWidget::~WelcomeWidget() delete ui; } +PlaylistInterface* +WelcomeWidget::playlistInterface() const +{ + return ui->tracksView->playlistInterface(); +} + + +bool +WelcomeWidget::jumpToCurrentTrack() +{ + return ui->tracksView->jumpToCurrentTrack(); +} + bool WelcomeWidget::isBeingPlayed() const { diff --git a/src/libtomahawk/widgets/welcomewidget.h b/src/libtomahawk/widgets/welcomewidget.h index 0dc92f040..bc4bcc24e 100644 --- a/src/libtomahawk/widgets/welcomewidget.h +++ b/src/libtomahawk/widgets/welcomewidget.h @@ -84,7 +84,7 @@ public: ~WelcomeWidget(); virtual QWidget* widget() { return this; } - virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + virtual Tomahawk::PlaylistInterface* playlistInterface() const; virtual QString title() const { return tr( "Welcome to Tomahawk" ); } virtual QString description() const { return QString(); } @@ -92,7 +92,7 @@ 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: diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 7cb374e66..9e5717eec 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -18,6 +18,7 @@ */ #include "whatshotwidget.h" +#include "whatshotwidget_p.h" #include "ui_whatshotwidget.h" #include @@ -50,6 +51,7 @@ static QString s_whatsHotIdentifier = QString( "WhatsHotWidget" ); WhatsHotWidget::WhatsHotWidget( QWidget* parent ) : QWidget( parent ) , ui( new Ui::WhatsHotWidget ) + , m_playlistInterface( 0 ) , m_sortedProxy( 0 ) { ui->setupUi( this ); @@ -90,6 +92,8 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->artistsViewLeft->header()->setVisible( false ); + m_playlistInterface = new ChartsPlaylistInterface( this ); + connect( Tomahawk::InfoSystem::InfoSystem::instance(), SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); @@ -102,9 +106,16 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) WhatsHotWidget::~WhatsHotWidget() { + delete m_playlistInterface; delete ui; } +PlaylistInterface* +WhatsHotWidget::playlistInterface() const +{ + return m_playlistInterface; +} + bool WhatsHotWidget::isBeingPlayed() const diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index ecd0be8ef..392c39a32 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -31,6 +31,7 @@ #include "dllmacro.h" +class ChartsPlaylistInterface; class QSortFilterProxyModel; class QStandardItemModel; class QStandardItem; @@ -58,7 +59,7 @@ public: ~WhatsHotWidget(); virtual QWidget* widget() { return this; } - virtual Tomahawk::PlaylistInterface* playlistInterface() const { return 0; } + virtual Tomahawk::PlaylistInterface* playlistInterface() const; virtual QString title() const { return tr( "Charts" ); } virtual QString description() const { return QString(); } @@ -90,6 +91,7 @@ private: QStandardItem* parseNode( QStandardItem* parentItem, const QString &label, const QVariant &data ); Ui::WhatsHotWidget *ui; + ChartsPlaylistInterface* m_playlistInterface; QStandardItemModel* m_crumbModelLeft; QSortFilterProxyModel* m_sortedProxy; @@ -101,6 +103,8 @@ private: QString m_queueItemToShow; QSet< QString > m_queuedFetches; QTimer* m_timer; + + friend class ChartsPlaylistInterface; }; #endif // WHATSHOTWIDGET_H diff --git a/src/libtomahawk/widgets/whatshotwidget_p.h b/src/libtomahawk/widgets/whatshotwidget_p.h new file mode 100644 index 000000000..e4e3d8dc4 --- /dev/null +++ b/src/libtomahawk/widgets/whatshotwidget_p.h @@ -0,0 +1,107 @@ +/* === 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 WHATSHOTWIDGET_P_H +#define WHATSHOTWIDGET_P_H + +#include "whatshotwidget.h" +#include "playlistinterface.h" +#include "ui_whatshotwidget.h" +#include "treeproxymodel.h" +#include "playlistview.h" +#include "result.h" + +#include + +class ChartsPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +{ + Q_OBJECT +public: + explicit ChartsPlaylistInterface( WhatsHotWidget* w ) + : PlaylistInterface( this ) + , m_w( w ) + { + connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); + connect( m_w->ui->artistsViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + SLOT( anyRepeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); + + connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ), + SLOT( anyShuffleChanged( bool ) ) ); + connect( m_w->ui->artistsViewLeft->proxyModel(), SIGNAL( shuffleModeChanged( bool ) ), + SLOT( anyShuffleChanged( bool ) ) ); + } + virtual ~ChartsPlaylistInterface() {} + + + // Any one is fine, we keep them all synched + virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->repeatMode(); } + + virtual bool shuffled() const { return m_w->ui->tracksViewLeft->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; } + + virtual bool hasChildInterface( PlaylistInterface* other ) + { + return m_w->ui->tracksViewLeft->playlistInterface() == other || + m_w->ui->artistsViewLeft->playlistInterface() == other; + + } +public slots: + virtual void setRepeatMode( RepeatMode mode ) + { + m_w->ui->tracksViewLeft->proxyModel()->setRepeatMode( mode ); + m_w->ui->artistsViewLeft->proxyModel()->setRepeatMode( mode ); + } + + virtual void setShuffled( bool enabled ) + { + m_w->ui->tracksViewLeft->proxyModel()->setShuffled( enabled ); + m_w->ui->artistsViewLeft->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: + WhatsHotWidget* m_w; + +}; + +#endif