diff --git a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp index 50bd25124..75a7a8f66 100644 --- a/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp +++ b/src/libtomahawk/infosystem/infoplugins/generic/chartsplugin.cpp @@ -279,6 +279,7 @@ ChartsPlugin::chartTypes() // We'll populate charts with the data from the server QVariantMap charts; QString chartName; + QStringList defaultChain; if ( source == "itunes" ) { // 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(); QString name = chart.value( "name" ).toString(); const QString type = chart.value( "type" ).toString(); + const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); QString country; if ( !m_cachedCountries.contains( geo ) ) @@ -321,10 +323,20 @@ ChartsPlugin::chartTypes() c[ "id" ] = id; c[ "label" ] = name; c[ "type" ] = "album"; + if ( isDefault ) + c[ "default" ] = "true"; + QList countryTypeData = countries[ country ][ type ].value< QList< InfoStringHash > >(); countryTypeData.append( c ); 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() ) @@ -344,9 +356,14 @@ ChartsPlugin::chartTypes() { const QVariantMap chart = chartObj.toMap(); const QString type = chart.value( "type" ).toString(); + const bool isDefault = ( chart.contains( "default" ) && chart[ "default" ].toInt() == 1 ); + InfoStringHash c; c[ "id" ] = chart.value( "id" ).toString(); c[ "label" ] = chart.value( "name" ).toString(); + if ( isDefault ) + c[ "default" ] = "true"; + if ( type == "Album" ) { c[ "type" ] = "album"; @@ -357,6 +374,13 @@ ChartsPlugin::chartTypes() c[ "type" ] = "tracks"; 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( "Tracks" ), QVariant::fromValue< QList< InfoStringHash > >( trackCharts ) ); @@ -369,6 +393,10 @@ ChartsPlugin::chartTypes() /// Add the possible charts and its types to breadcrumb // 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 ) ); } diff --git a/src/libtomahawk/widgets/siblingcrumbbutton.cpp b/src/libtomahawk/widgets/siblingcrumbbutton.cpp index f11704aac..e6f4f6e49 100644 --- a/src/libtomahawk/widgets/siblingcrumbbutton.cpp +++ b/src/libtomahawk/widgets/siblingcrumbbutton.cpp @@ -27,6 +27,7 @@ #include #include #include +#include "whatshotwidget.h" BreadcrumbButtonBase* SiblingCrumbButtonFactory::newButton(QModelIndex index, BreadcrumbBar *parent) { @@ -129,10 +130,16 @@ void SiblingCrumbButton::fillCombo() { QStringList list; 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); - if( sibling.isValid() ) + if ( sibling.isValid() ) + { list << sibling.data().toString(); + if ( sibling.data( WhatsHotWidget::DefaultRole ).toBool() ) + defaultIndex = i; + } } if ( m_combo->count() && list.count() ) @@ -148,7 +155,13 @@ void SiblingCrumbButton::fillCombo() m_combo->clear(); m_combo->addItems(list); - m_combo->setCurrentIndex( m_combo->findText(text())); + if ( defaultIndex == -1 ) + m_combo->setCurrentIndex( m_combo->findText(text())); + else + { + m_combo->setCurrentIndex( defaultIndex ); + comboboxActivated( defaultIndex ); + } m_combo->adjustSize(); } diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 89a113fa1..e1a7a0a83 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -171,7 +171,12 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat QStandardItem *rootItem= m_crumbModelLeft->invisibleRootItem(); tDebug( LOGVERBOSE ) << "WhatsHot:: " << returnedData.keys(); - foreach( const QString label, 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() ) { tDebug( LOGVERBOSE ) << "WhatsHot:: parsing " << label; QStandardItem *childItem = parseNode( rootItem, label, returnedData[label] ); @@ -179,9 +184,40 @@ WhatsHotWidget::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestDat 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); ui->breadCrumbLeft->setSelectionModel(selectionModelLeft); - //ui->breadCrumbRight->setSelectionModel(selectionModelLeft); break; } @@ -368,6 +404,8 @@ WhatsHotWidget::parseNode( QStandardItem* parentItem, const QString &label, cons { QStandardItem *childItem= new QStandardItem( chart[ "label" ] ); childItem->setData( chart[ "id" ] ); + if ( chart.value( "default", "" ) == "true") + sourceItem->setData( WhatsHotWidget::DefaultRole, true ); sourceItem->appendRow( childItem ); } } @@ -386,7 +424,6 @@ WhatsHotWidget::parseNode( QStandardItem* parentItem, const QString &label, cons foreach ( const QVariant value, dataList ) { - qDebug() << "CREATED:" << value.toString(); QStandardItem *childItem= new QStandardItem(value.toString()); sourceItem->appendRow(childItem); } diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index e13c0421e..332014d31 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -53,6 +53,10 @@ class DLLEXPORT WhatsHotWidget : public QWidget, public Tomahawk::ViewPage Q_OBJECT public: + enum ExtraRoles { + DefaultRole = Qt::UserRole + 10 + }; + WhatsHotWidget( QWidget* parent = 0 ); ~WhatsHotWidget();