1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-29 16:50:11 +02:00

Use last seen chart as default, add loading spinner

This commit is contained in:
Hugo Lindström
2012-09-25 20:40:38 +02:00
parent 8103019a8d
commit 7ec8652134
2 changed files with 43 additions and 22 deletions

View File

@@ -42,6 +42,7 @@
#include "utils/TomahawkUtilsGui.h" #include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h" #include "utils/Logger.h"
#include "Pipeline.h" #include "Pipeline.h"
#include "utils/AnimatedSpinner.h"
#define HISTORY_TRACK_ITEMS 25 #define HISTORY_TRACK_ITEMS 25
#define HISTORY_PLAYLIST_ITEMS 10 #define HISTORY_PLAYLIST_ITEMS 10
@@ -106,6 +107,12 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
// Read last viewed charts, to be used as defaults // Read last viewed charts, to be used as defaults
m_currentVIds = TomahawkSettings::instance()->lastChartIds(); m_currentVIds = TomahawkSettings::instance()->lastChartIds();
qDebug() << "Got last chartIds:" << m_currentVIds; qDebug() << "Got last chartIds:" << m_currentVIds;
// TracksView is first shown, show spinner on that
// After fadeOut, charts are loaded
m_loadingSpinner = new AnimatedSpinner( ui->tracksViewLeft );
m_loadingSpinner->fadeIn();
} }
@@ -165,6 +172,7 @@ WhatsHotWidget::jumpToCurrentTrack()
void void
WhatsHotWidget::fetchData() WhatsHotWidget::fetchData()
{ {
Tomahawk::InfoSystem::InfoStringHash artistInfo; Tomahawk::InfoSystem::InfoStringHash artistInfo;
Tomahawk::InfoSystem::InfoRequestData requestData; Tomahawk::InfoSystem::InfoRequestData requestData;
@@ -207,10 +215,14 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
QVariantMap defaults; QVariantMap defaults;
if ( returnedData.contains( "defaults" ) ) if ( returnedData.contains( "defaults" ) )
defaults = returnedData.take( "defaults" ).toMap(); defaults = returnedData.take( "defaults" ).toMap();
QString defaultSource = returnedData.take( "defaultSource" ).toString();
qDebug() << "Have defaultmap" << defaults; // We need to take this from data
qDebug() << "Have customDefault" << m_currentVIds; QString defaultSource = returnedData.take( "defaultSource" ).toString();
// Here, we dont want current sessions last view, but rather what was current on previus quit
QString lastSeen = TomahawkSettings::instance()->lastChartIds().value( "lastseen" ).toString();
if( !lastSeen.isEmpty() )
defaultSource = lastSeen;
// Merge defaults with current defaults, split the value in to a list // Merge defaults with current defaults, split the value in to a list
foreach( const QString&key, m_currentVIds.keys() ) foreach( const QString&key, m_currentVIds.keys() )
defaults[ key ] = m_currentVIds.value( key ).toString().split( "/" ); defaults[ key ] = m_currentVIds.value( key ).toString().split( "/" );
@@ -223,29 +235,32 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
// Set the default source // Set the default source
// Set the default chart for each source // Set the default chart for each source
for ( int i = 0; i < rootItem->rowCount(); i++ ) if( !defaults.empty() )
{ {
QStandardItem* source = rootItem->child( i, 0 ); for ( int i = 0; i < rootItem->rowCount(); i++ )
if ( defaultSource.toLower() == source->text().toLower() )
{ {
source->setData( true, Breadcrumb::DefaultRole ); QStandardItem* source = rootItem->child( i, 0 );
} if ( defaultSource.toLower() == source->text().toLower() )
if ( defaults.contains( source->text().toLower() ) )
{
QStringList defaultIndices = defaults[ source->text().toLower() ].toStringList();
QStandardItem* cur = source;
foreach( const QString& index, defaultIndices )
{ {
// Go through the children of the current item, marking the default one as default source->setData( true, Breadcrumb::DefaultRole );
for ( int k = 0; k < cur->rowCount(); k++ ) }
if ( defaults.contains( source->text().toLower() ) )
{
QStringList defaultIndices = defaults[ source->text().toLower() ].toStringList();
QStandardItem* cur = source;
foreach( const QString& index, defaultIndices )
{ {
if ( cur->child( k, 0 )->text().toLower() == index.toLower() ) // Go through the children of the current item, marking the default one as default
for ( int k = 0; k < cur->rowCount(); k++ )
{ {
cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default if ( cur->child( k, 0 )->text().toLower() == index.toLower() )
cur->setData( true, Breadcrumb::DefaultRole ); {
break; cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default
cur->setData( true, Breadcrumb::DefaultRole );
break;
}
} }
} }
} }
@@ -319,6 +334,7 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
if ( m_queueItemToShow == chartId ) if ( m_queueItemToShow == chartId )
setLeftViewTracks( trackModel ); setLeftViewTracks( trackModel );
} }
QMetaObject::invokeMethod( loader, "go", Qt::QueuedConnection ); QMetaObject::invokeMethod( loader, "go", Qt::QueuedConnection );
@@ -335,12 +351,14 @@ void
WhatsHotWidget::infoSystemFinished( QString target ) WhatsHotWidget::infoSystemFinished( QString target )
{ {
Q_UNUSED( target ); Q_UNUSED( target );
m_loadingSpinner->fadeOut();
} }
void void
WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index ) WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
{ {
tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data(); tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data();
QStandardItem* item = m_crumbModelLeft->itemFromIndex( m_sortedProxy->mapToSource( index ) ); QStandardItem* item = m_crumbModelLeft->itemFromIndex( m_sortedProxy->mapToSource( index ) );
@@ -368,6 +386,7 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
// Write the current view // Write the current view
m_currentVIds[ chartSource ] = curr.join( "/" ); // Instead of keeping an array, join and split later m_currentVIds[ chartSource ] = curr.join( "/" ); // Instead of keeping an array, join and split later
m_currentVIds[ "lastseen" ] = chartSource; // We keep a record of last seen
if ( m_artistModels.contains( chartId ) ) if ( m_artistModels.contains( chartId ) )
{ {
@@ -490,6 +509,7 @@ WhatsHotWidget::setLeftViewAlbums( PlayableModel* model )
ui->albumsView->setPlayableModel( model ); ui->albumsView->setPlayableModel( model );
ui->albumsView->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel ui->albumsView->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel
ui->stackLeft->setCurrentIndex( 2 ); ui->stackLeft->setCurrentIndex( 2 );
} }

View File

@@ -38,7 +38,7 @@ class TreeModel;
class PlaylistModel; class PlaylistModel;
class TreeProxyModel; class TreeProxyModel;
class PlayableModel; class PlayableModel;
class AnimatedSpinner;
namespace Ui namespace Ui
{ {
class WhatsHotWidget; class WhatsHotWidget;
@@ -119,6 +119,7 @@ private:
QSet< QString > m_queuedFetches; QSet< QString > m_queuedFetches;
QTimer* m_timer; QTimer* m_timer;
QMap<QString, QVariant> m_currentVIds; QMap<QString, QVariant> m_currentVIds;
AnimatedSpinner* m_loadingSpinner;
friend class Tomahawk::ChartsPlaylistInterface; friend class Tomahawk::ChartsPlaylistInterface;
}; };