From d65aab970200e1c11172a5a949d0690564733336 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 25 Sep 2014 12:29:32 +0200 Subject: [PATCH] add GenrePreset, try to register Genre & Genres as Qt MetaTypes to allow storing in cache --- .../dynamic/echonest/EchonestControl.cpp | 70 ++++++++++++++++++- .../dynamic/echonest/EchonestGenerator.cpp | 2 + 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index 80af95037..f1a7f2d78 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -516,7 +516,7 @@ Tomahawk::EchonestControl::updateWidgets() QLabel* match = new QLabel( tr( "is" ) ); QComboBox* combo = new QComboBox(); - combo->addItem( tr( "Focused", "Distribution: Songs that are tightly clustered around the seeds"), "focused" ); + combo->addItem( tr( "Focused", "Distribution: Songs that are tightly clustered around the seeds" ), "focused" ); combo->addItem( tr( "Wandering", "Distribution: Songs from a broader range of artists"), "wandering" ); m_matchString = match->text(); @@ -528,6 +528,30 @@ Tomahawk::EchonestControl::updateWidgets() m_match = QPointer( match ); m_input = QPointer( combo ); } + else if( selectedType() == "Genre Preset" ) + { + m_currentType = Echonest::DynamicPlaylist::GenrePreset; + + QComboBox* match = new QComboBox(); + match->addItem( tr( "Classics", "Genre preset: songs intended to introduce the genre to a novice listener" ), "core" ); + match->addItem( tr( "Popular", "Genre preset: most popular songs being played in the genre today" ), "in_rotation" ); + match->addItem( tr( "Emerging", "Genre preset: songs that are more popular than expected, but which are unfamiliar to most listeners" ), "emerging" ); + + QComboBox* combo = new QComboBox(); + combo->addItem( tr( "Best", "Genre preset: optimal collection of songs" ), "best" ); + combo->addItem( tr( "Mix", "Genre preset: a varying collection of songs" ), "shuffled" ); + + m_matchString = match->currentText(); + m_matchData = match->itemData( match->currentIndex() ).toString(); + + connect( match, SIGNAL( activated( int ) ), this, SLOT( updateData() ) ); + connect( match, SIGNAL( activated( int ) ), this, SLOT( editingFinished() ) ); + connect( combo, SIGNAL( activated( int ) ), this, SLOT( updateData() ) ); + connect( combo, SIGNAL( activated( int ) ), this, SLOT( editingFinished() ) ); + + m_match = QPointer( match ); + m_input = QPointer( combo ); + } else { m_match = QPointer( new QWidget ); @@ -655,7 +679,22 @@ Tomahawk::EchonestControl::updateData() m_data.second = combo->itemData( combo->currentIndex() ).toString(); } } + else if( selectedType() == "Genre Preset" ) + { + QComboBox* match = qobject_cast( m_match.data() ); + QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() ); + if ( match && combo ) + { + m_matchString = match->currentText(); + m_matchData = match->itemData( match->currentIndex() ).toString(); + QString presetType = m_matchData.append( "_%1" ); + presetType = presetType.arg( combo->itemData( combo->currentIndex() ).toString() ); + + m_data.first = Echonest::DynamicPlaylist::GenrePreset; + m_data.second = presetType; + } + } calculateSummary(); } @@ -1048,6 +1087,35 @@ Tomahawk::EchonestControl::calculateSummary() summary = tr( "with a %1 distribution" ).arg( text ); } + else if( selectedType() == "Genre Preset" ) + { + Q_ASSERT( !m_input.isNull() ); + Q_ASSERT( qobject_cast< QComboBox* >( m_input.data() ) ); + QComboBox* input = qobject_cast< QComboBox* >( m_input.data() ); + + Q_ASSERT( !m_match.isNull() ); + Q_ASSERT( qobject_cast< QComboBox* >( m_match.data() ) ); + QComboBox* match = qobject_cast< QComboBox* >( m_match.data() ); + + summary = tr( "preset to %1 collection of %2 genre songs" ); + if ( input->itemData( input->currentIndex() ) == "best" ) + summary = summary.arg( tr( "an optimal" ) ); + else + summary = summary.arg( tr( "a mixed" ) ); + + if ( match->itemData( match->currentIndex() ) == "core" ) + { + summary = summary.arg( tr( "classic" ) ); + } + else + { + if ( match->itemData( match->currentIndex() ) == "in_rotation" ) + summary = summary.arg( tr( "popular" ) ); + else + summary = summary.arg( tr( "emerging" ) ); + } + } + m_summary = summary; } diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index da3f7fe3a..bbd7881be 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -808,6 +808,8 @@ EchonestGenerator::genresReceived() } s_genresJob = 0; + qRegisterMetaType< Echonest::Genre >( "enGenre" ); + qRegisterMetaType< Echonest::Genres >( "enGenres" ); TomahawkUtils::Cache::instance()->putData( "EchonestGenerator", 1209600000 /* 2 weeks */, "genres", QVariant::fromValue< Echonest::Genres >( s_genres ) ); s_genres_lock.unlock(); emit genresSaved();