mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-29 08:40:40 +02:00
Use last seen chart as default, add loading spinner
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
#include "utils/TomahawkUtilsGui.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "Pipeline.h"
|
||||
#include "utils/AnimatedSpinner.h"
|
||||
|
||||
#define HISTORY_TRACK_ITEMS 25
|
||||
#define HISTORY_PLAYLIST_ITEMS 10
|
||||
@@ -106,6 +107,12 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent )
|
||||
// Read last viewed charts, to be used as defaults
|
||||
m_currentVIds = TomahawkSettings::instance()->lastChartIds();
|
||||
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
|
||||
WhatsHotWidget::fetchData()
|
||||
{
|
||||
|
||||
Tomahawk::InfoSystem::InfoStringHash artistInfo;
|
||||
|
||||
Tomahawk::InfoSystem::InfoRequestData requestData;
|
||||
@@ -207,10 +215,14 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
||||
QVariantMap defaults;
|
||||
if ( returnedData.contains( "defaults" ) )
|
||||
defaults = returnedData.take( "defaults" ).toMap();
|
||||
QString defaultSource = returnedData.take( "defaultSource" ).toString();
|
||||
|
||||
qDebug() << "Have defaultmap" << defaults;
|
||||
qDebug() << "Have customDefault" << m_currentVIds;
|
||||
// We need to take this from data
|
||||
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
|
||||
foreach( const QString&key, m_currentVIds.keys() )
|
||||
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 chart for each source
|
||||
for ( int i = 0; i < rootItem->rowCount(); i++ )
|
||||
if( !defaults.empty() )
|
||||
{
|
||||
QStandardItem* source = rootItem->child( i, 0 );
|
||||
if ( defaultSource.toLower() == source->text().toLower() )
|
||||
for ( int i = 0; i < rootItem->rowCount(); i++ )
|
||||
{
|
||||
source->setData( true, Breadcrumb::DefaultRole );
|
||||
}
|
||||
|
||||
if ( defaults.contains( source->text().toLower() ) )
|
||||
{
|
||||
QStringList defaultIndices = defaults[ source->text().toLower() ].toStringList();
|
||||
QStandardItem* cur = source;
|
||||
|
||||
foreach( const QString& index, defaultIndices )
|
||||
QStandardItem* source = rootItem->child( i, 0 );
|
||||
if ( defaultSource.toLower() == source->text().toLower() )
|
||||
{
|
||||
// Go through the children of the current item, marking the default one as default
|
||||
for ( int k = 0; k < cur->rowCount(); k++ )
|
||||
source->setData( true, Breadcrumb::DefaultRole );
|
||||
}
|
||||
|
||||
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
|
||||
cur->setData( true, Breadcrumb::DefaultRole );
|
||||
break;
|
||||
if ( cur->child( k, 0 )->text().toLower() == index.toLower() )
|
||||
{
|
||||
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 )
|
||||
setLeftViewTracks( trackModel );
|
||||
|
||||
}
|
||||
|
||||
QMetaObject::invokeMethod( loader, "go", Qt::QueuedConnection );
|
||||
@@ -335,12 +351,14 @@ void
|
||||
WhatsHotWidget::infoSystemFinished( QString target )
|
||||
{
|
||||
Q_UNUSED( target );
|
||||
m_loadingSpinner->fadeOut();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
|
||||
{
|
||||
|
||||
tDebug( LOGVERBOSE ) << "WhatsHot:: left crumb changed" << index.data();
|
||||
|
||||
QStandardItem* item = m_crumbModelLeft->itemFromIndex( m_sortedProxy->mapToSource( index ) );
|
||||
@@ -368,6 +386,7 @@ WhatsHotWidget::leftCrumbIndexChanged( QModelIndex index )
|
||||
|
||||
// Write the current view
|
||||
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 ) )
|
||||
{
|
||||
@@ -490,6 +509,7 @@ WhatsHotWidget::setLeftViewAlbums( PlayableModel* model )
|
||||
ui->albumsView->setPlayableModel( model );
|
||||
ui->albumsView->proxyModel()->sort( -1 ); // disable sorting, must be called after artistsViewLeft->setTreeModel
|
||||
ui->stackLeft->setCurrentIndex( 2 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -38,7 +38,7 @@ class TreeModel;
|
||||
class PlaylistModel;
|
||||
class TreeProxyModel;
|
||||
class PlayableModel;
|
||||
|
||||
class AnimatedSpinner;
|
||||
namespace Ui
|
||||
{
|
||||
class WhatsHotWidget;
|
||||
@@ -119,6 +119,7 @@ private:
|
||||
QSet< QString > m_queuedFetches;
|
||||
QTimer* m_timer;
|
||||
QMap<QString, QVariant> m_currentVIds;
|
||||
AnimatedSpinner* m_loadingSpinner;
|
||||
friend class Tomahawk::ChartsPlaylistInterface;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user