mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Set two default items for the charts
try listening to any changed and set default source don't listen to indexchanged, do a manual set when setting default
This commit is contained in:
@@ -279,6 +279,7 @@ ChartsPlugin::chartTypes()
|
|||||||
// We'll populate charts with the data from the server
|
// We'll populate charts with the data from the server
|
||||||
QVariantMap charts;
|
QVariantMap charts;
|
||||||
QString chartName;
|
QString chartName;
|
||||||
|
QStringList defaultChain;
|
||||||
if ( source == "itunes" )
|
if ( source == "itunes" )
|
||||||
{
|
{
|
||||||
// Itunes has geographic-area based charts. So we build a breadcrumb of
|
// Itunes has geographic-area based charts. So we build a breadcrumb of
|
||||||
@@ -292,6 +293,7 @@ ChartsPlugin::chartTypes()
|
|||||||
const QString geo = chart.value( "geo" ).toString();
|
const QString geo = chart.value( "geo" ).toString();
|
||||||
QString name = chart.value( "name" ).toString();
|
QString name = chart.value( "name" ).toString();
|
||||||
const QString type = chart.value( "type" ).toString();
|
const QString type = chart.value( "type" ).toString();
|
||||||
|
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
|
||||||
|
|
||||||
QString country;
|
QString country;
|
||||||
if ( !m_cachedCountries.contains( geo ) )
|
if ( !m_cachedCountries.contains( geo ) )
|
||||||
@@ -321,10 +323,20 @@ ChartsPlugin::chartTypes()
|
|||||||
c[ "id" ] = id;
|
c[ "id" ] = id;
|
||||||
c[ "label" ] = name;
|
c[ "label" ] = name;
|
||||||
c[ "type" ] = "album";
|
c[ "type" ] = "album";
|
||||||
|
if ( isDefault )
|
||||||
|
c[ "default" ] = "true";
|
||||||
|
|
||||||
QList<InfoStringHash> countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >();
|
QList<InfoStringHash> countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >();
|
||||||
countryTypeData.append( c );
|
countryTypeData.append( c );
|
||||||
|
|
||||||
countries[ country ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( countryTypeData ) );
|
countries[ country ].insert( type, QVariant::fromValue< QList< InfoStringHash > >( countryTypeData ) );
|
||||||
|
if ( isDefault )
|
||||||
|
{
|
||||||
|
defaultChain.clear();
|
||||||
|
defaultChain.append( country );
|
||||||
|
defaultChain.append( type );
|
||||||
|
defaultChain.append( name );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( const QString& c, countries.keys() )
|
foreach( const QString& c, countries.keys() )
|
||||||
@@ -344,9 +356,14 @@ ChartsPlugin::chartTypes()
|
|||||||
{
|
{
|
||||||
const QVariantMap chart = chartObj.toMap();
|
const QVariantMap chart = chartObj.toMap();
|
||||||
const QString type = chart.value( "type" ).toString();
|
const QString type = chart.value( "type" ).toString();
|
||||||
|
const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 );
|
||||||
|
|
||||||
InfoStringHash c;
|
InfoStringHash c;
|
||||||
c[ "id" ] = chart.value( "id" ).toString();
|
c[ "id" ] = chart.value( "id" ).toString();
|
||||||
c[ "label" ] = chart.value( "name" ).toString();
|
c[ "label" ] = chart.value( "name" ).toString();
|
||||||
|
if ( isDefault )
|
||||||
|
c[ "default" ] = "true";
|
||||||
|
|
||||||
if ( type == "Album" )
|
if ( type == "Album" )
|
||||||
{
|
{
|
||||||
c[ "type" ] = "album";
|
c[ "type" ] = "album";
|
||||||
@@ -357,6 +374,13 @@ ChartsPlugin::chartTypes()
|
|||||||
c[ "type" ] = "tracks";
|
c[ "type" ] = "tracks";
|
||||||
trackCharts.append( c );
|
trackCharts.append( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( isDefault )
|
||||||
|
{
|
||||||
|
defaultChain.clear();
|
||||||
|
defaultChain.append( type + "s" ); //UGLY but it's plural to the user, see below
|
||||||
|
defaultChain.append( c[ "label" ] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) );
|
charts.insert( tr( "Albums" ), QVariant::fromValue< QList< InfoStringHash > >( albumCharts ) );
|
||||||
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) );
|
charts.insert( tr( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) );
|
||||||
@@ -369,6 +393,10 @@ ChartsPlugin::chartTypes()
|
|||||||
|
|
||||||
/// Add the possible charts and its types to breadcrumb
|
/// Add the possible charts and its types to breadcrumb
|
||||||
// qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName;
|
// qDebug() << "ADDING CHART TYPE TO CHARTS:" << chartName;
|
||||||
|
QVariantMap defaultMap = m_allChartsMap.value( "defaults" ).value< QVariantMap >();
|
||||||
|
defaultMap[ source ] = defaultChain;
|
||||||
|
m_allChartsMap[ "defaults" ] = defaultMap;
|
||||||
|
m_allChartsMap[ "defaultSource" ] = "itunes";
|
||||||
m_allChartsMap.insert( chartName , QVariant::fromValue< QVariantMap >( charts ) );
|
m_allChartsMap.insert( chartName , QVariant::fromValue< QVariantMap >( charts ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QStyle>
|
#include <QStyle>
|
||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
|
#include "whatshotwidget.h"
|
||||||
|
|
||||||
BreadcrumbButtonBase* SiblingCrumbButtonFactory::newButton(QModelIndex index, BreadcrumbBar *parent)
|
BreadcrumbButtonBase* SiblingCrumbButtonFactory::newButton(QModelIndex index, BreadcrumbBar *parent)
|
||||||
{
|
{
|
||||||
@@ -129,10 +130,16 @@ void SiblingCrumbButton::fillCombo()
|
|||||||
{
|
{
|
||||||
QStringList list;
|
QStringList list;
|
||||||
int count = breadcrumbBar()->model()->rowCount(m_index.parent());
|
int count = breadcrumbBar()->model()->rowCount(m_index.parent());
|
||||||
for(int i = 0; i < count; ++i) {
|
int defaultIndex = -1;
|
||||||
|
for ( int i = 0; i < count; ++i )
|
||||||
|
{
|
||||||
QModelIndex sibling = m_index.sibling(i,0);
|
QModelIndex sibling = m_index.sibling(i,0);
|
||||||
if ( sibling.isValid() )
|
if ( sibling.isValid() )
|
||||||
|
{
|
||||||
list << sibling.data().toString();
|
list << sibling.data().toString();
|
||||||
|
if ( sibling.data( WhatsHotWidget::DefaultRole ).toBool() )
|
||||||
|
defaultIndex = i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_combo->count() && list.count() )
|
if ( m_combo->count() && list.count() )
|
||||||
@@ -148,7 +155,13 @@ void SiblingCrumbButton::fillCombo()
|
|||||||
|
|
||||||
m_combo->clear();
|
m_combo->clear();
|
||||||
m_combo->addItems(list);
|
m_combo->addItems(list);
|
||||||
|
if ( defaultIndex == -1 )
|
||||||
m_combo->setCurrentIndex( m_combo->findText(text()));
|
m_combo->setCurrentIndex( m_combo->findText(text()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_combo->setCurrentIndex( defaultIndex );
|
||||||
|
comboboxActivated( defaultIndex );
|
||||||
|
}
|
||||||
m_combo->adjustSize();
|
m_combo->adjustSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -171,6 +171,11 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem();
|
QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem();
|
||||||
tDebug( LOGVERBOSE ) << "WhatsHot:: " << returnedData.keys();
|
tDebug( LOGVERBOSE ) << "WhatsHot:: " << returnedData.keys();
|
||||||
|
|
||||||
|
QVariantMap defaults;
|
||||||
|
if ( returnedData.contains( "defaults" ) )
|
||||||
|
defaults = returnedData.take( "defaults" ).toMap();
|
||||||
|
QString defaultSource = returnedData.take( "defaultSource" ).toString();
|
||||||
|
|
||||||
foreach ( const QString label, returnedData.keys() )
|
foreach ( const QString label, returnedData.keys() )
|
||||||
{
|
{
|
||||||
tDebug( LOGVERBOSE ) << "WhatsHot:: parsing " << label;
|
tDebug( LOGVERBOSE ) << "WhatsHot:: parsing " << label;
|
||||||
@@ -179,9 +184,40 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat
|
|||||||
rootItem->appendRow(childItem);
|
rootItem->appendRow(childItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the default source
|
||||||
|
// Set the default chart for each source
|
||||||
|
for ( int i = 0; i < rootItem->rowCount(); i++ )
|
||||||
|
{
|
||||||
|
QStandardItem* source = rootItem->child( i, 0 );
|
||||||
|
if ( defaultSource.toLower() == source->text().toLower() )
|
||||||
|
{
|
||||||
|
source->setData( true, DefaultRole );
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
for ( int k = 0; k < cur->rowCount(); k++ )
|
||||||
|
{
|
||||||
|
if ( cur->child( k, 0 )->text() == index )
|
||||||
|
{
|
||||||
|
// tDebug() << "Found DEFAULT ITEM:" << index;
|
||||||
|
cur = cur->child( k, 0 ); // this is the default, drill down into the default to pick the next default
|
||||||
|
cur->setData( true, DefaultRole );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
|
KBreadcrumbSelectionModel *selectionModelLeft = new KBreadcrumbSelectionModel(new QItemSelectionModel(m_crumbModelLeft, this), this);
|
||||||
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
|
ui->breadCrumbLeft->setSelectionModel(selectionModelLeft);
|
||||||
|
|
||||||
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
|
//ui->breadCrumbRight->setSelectionModel(selectionModelLeft);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -368,6 +404,8 @@ WhatsHotWidget::parseNode( QStandardItem* parentItem, const QString &label, cons
|
|||||||
{
|
{
|
||||||
QStandardItem *childItem= new QStandardItem( chart[ "label" ] );
|
QStandardItem *childItem= new QStandardItem( chart[ "label" ] );
|
||||||
childItem->setData( chart[ "id" ] );
|
childItem->setData( chart[ "id" ] );
|
||||||
|
if ( chart.value( "default", "" ) == "true")
|
||||||
|
sourceItem->setData( WhatsHotWidget::DefaultRole, true );
|
||||||
sourceItem->appendRow( childItem );
|
sourceItem->appendRow( childItem );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -386,7 +424,6 @@ WhatsHotWidget::parseNode( QStandardItem* parentItem, const QString &label, cons
|
|||||||
|
|
||||||
foreach ( const QVariant value, dataList )
|
foreach ( const QVariant value, dataList )
|
||||||
{
|
{
|
||||||
qDebug() << "CREATED:" << value.toString();
|
|
||||||
QStandardItem *childItem= new QStandardItem(value.toString());
|
QStandardItem *childItem= new QStandardItem(value.toString());
|
||||||
sourceItem->appendRow(childItem);
|
sourceItem->appendRow(childItem);
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,10 @@ class DLLEXPORT WhatsHotWidget : public QWidget, public Tomahawk::ViewPage
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum ExtraRoles {
|
||||||
|
DefaultRole = Qt::UserRole + 10
|
||||||
|
};
|
||||||
|
|
||||||
WhatsHotWidget( QWidget* parent = 0 );
|
WhatsHotWidget( QWidget* parent = 0 );
|
||||||
~WhatsHotWidget();
|
~WhatsHotWidget();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user