From 2f591f89d2b9c194cbcd18af3e5304fffee8d51b Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Sat, 1 Dec 2012 14:43:04 +0100 Subject: [PATCH 1/5] First Implementation of SongType support in Playlists (needs libechonest from https://github.com/Horrendus/libechonest) --- .../dynamic/echonest/EchonestControl.cpp | 39 +++++++++++++++++++ .../dynamic/echonest/EchonestGenerator.cpp | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index d9983b846..e199c6cc9 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -441,6 +441,28 @@ Tomahawk::EchonestControl::updateWidgets() m_input = QWeakPointer< QWidget >( combo ); insertMoodsAndStyles(); + } else if( selectedType() == "Song Type" ) { + m_currentType = Echonest::DynamicPlaylist::SongType; + + QComboBox* match = new QComboBox(); + match->addItem( tr( "is" ), 1 ); + match->addItem( tr( "is not" ), 0 ); + + QComboBox* combo = new QComboBox(); + combo->addItem( tr( "Christmas" ), "christmas" ); + combo->addItem( tr( "Studio" ), "studio" ); + combo->addItem( tr( "Live" ), "live" ); + + 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_matchString = match->currentText(); + m_matchData = match->currentText(); + + m_match = QWeakPointer< QWidget >( match ); + m_input = QWeakPointer< QWidget >( combo ); } else { m_match = QWeakPointer( new QWidget ); m_input = QWeakPointer( new QWidget ); @@ -522,6 +544,23 @@ Tomahawk::EchonestControl::updateData() m_data.second = enumVal; // qDebug() << "SAVING" << input->currentIndex() << "AS" << enumVal << "(" << input->itemData( input->currentIndex() ).toInt() << "+" << m_matchData.toInt() << ")"; } + } else if( selectedType() == "Song Type" ) { + QComboBox* match = qobject_cast( m_match.data() ); + QComboBox* input = qobject_cast< QComboBox* >( m_input.data() ); + if ( match && input ) { + m_matchString = match->currentText(); + m_matchData = match->itemData( match->currentIndex() ).toString(); + + QString songType = input->currentText().toLower(); + if ( match->currentText() == "is not" ) + songType.append(":false"); + + qDebug() << "ST: " << songType; + + m_data.first = Echonest::DynamicPlaylist::SongType; + m_data.second = songType; + } + } calculateSummary(); diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index e581d7aff..61e648188 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -65,7 +65,7 @@ EchonestFactory::typeSelectors() const { QStringList types = QStringList() << "Artist" << "Artist Description" << "User Radio" << "Song" << "Mood" << "Style" << "Adventurousness" << "Variety" << "Tempo" << "Duration" << "Loudness" << "Danceability" << "Energy" << "Artist Familiarity" << "Artist Hotttnesss" << "Song Hotttnesss" - << "Longitude" << "Latitude" << "Mode" << "Key" << "Sorting"; + << "Longitude" << "Latitude" << "Mode" << "Key" << "Sorting" << "Song Type"; return types; } From f43fd2b3835662f6376b4b6eda7882845face051 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Sun, 2 Dec 2012 22:53:13 +0100 Subject: [PATCH 2/5] Added correct Widget Update after Startup & Summary Text for Song Type Support --- .../dynamic/echonest/EchonestControl.cpp | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index e199c6cc9..f40327ffb 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -449,17 +449,17 @@ Tomahawk::EchonestControl::updateWidgets() match->addItem( tr( "is not" ), 0 ); QComboBox* combo = new QComboBox(); - combo->addItem( tr( "Christmas" ), "christmas" ); combo->addItem( tr( "Studio" ), "studio" ); combo->addItem( tr( "Live" ), "live" ); + combo->addItem( tr( "Christmas" ), "christmas" ); 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_matchString = match->currentText(); - m_matchData = match->currentText(); + m_matchString = "is"; + m_matchData = 1; m_match = QWeakPointer< QWidget >( match ); m_input = QWeakPointer< QWidget >( combo ); @@ -546,17 +546,15 @@ Tomahawk::EchonestControl::updateData() } } else if( selectedType() == "Song Type" ) { QComboBox* match = qobject_cast( m_match.data() ); - QComboBox* input = qobject_cast< QComboBox* >( m_input.data() ); - if ( match && input ) { + QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() ); + if ( match && combo ) { m_matchString = match->currentText(); m_matchData = match->itemData( match->currentIndex() ).toString(); - QString songType = input->currentText().toLower(); + QString songType = combo->currentText().toLower(); if ( match->currentText() == "is not" ) songType.append(":false"); - qDebug() << "ST: " << songType; - m_data.first = Echonest::DynamicPlaylist::SongType; m_data.second = songType; } @@ -650,6 +648,15 @@ Tomahawk::EchonestControl::updateWidgetsFromData() input->setCurrentIndex( val ); // qDebug() << "LOADING" << m_data.second.toInt() << "AS" << val; } + } else if( selectedType() == "Song Type" ) { + QComboBox* match = qobject_cast( m_match.data() ); + QComboBox* combo = qobject_cast< QComboBox* >( m_input.data() ); + if ( match && combo ) { + match->setCurrentIndex( match->findData( m_matchData )); + + QString songType = m_data.second.toString().split(":").at(0); + combo->setCurrentIndex( combo->findData( songType ) ); + } } calculateSummary(); } @@ -862,6 +869,19 @@ Tomahawk::EchonestControl::calculateSummary() Q_ASSERT( qobject_cast< QComboBox* >( m_input.data() ) ); QString text = qobject_cast< QComboBox* >( m_input.data() )->currentText().toLower(); summary = tr( "in a %1 style" ).arg( text ); + } else if( selectedType() == "Song Type" ) { + Q_ASSERT( !m_input.isNull() ); + Q_ASSERT( qobject_cast< QComboBox* >( m_input.data() ) ); + QString text = qobject_cast< QComboBox* >( m_input.data() )->currentText(); + + + Q_ASSERT( !m_match.isNull() ); + Q_ASSERT( qobject_cast< QComboBox* >( m_match.data() ) ); + QString isOrIsNot = qobject_cast< QComboBox* >( m_match.data() )->currentText().toLower(); + if ( isOrIsNot == "is" ) + summary = tr( "where Song Type is %1" ).arg( text ); + else + summary = tr( "where Song Type is not %1" ).arg( text ); } m_summary = summary; } From e32d6c0adf4f7eb684f7327bbb6b1c47cb86d221 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Tue, 8 Jan 2013 13:24:11 +0100 Subject: [PATCH 3/5] Change QWeakPointer to QPointer to make it compile again --- src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index 518d45f5a..c1426af53 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -461,8 +461,8 @@ Tomahawk::EchonestControl::updateWidgets() m_matchString = "is"; m_matchData = 1; - m_match = QWeakPointer< QWidget >( match ); - m_input = QWeakPointer< QWidget >( combo ); + m_match = QPointer< QWidget >( match ); + m_input = QPointer< QWidget >( combo ); } else { m_match = QPointer( new QWidget ); m_input = QPointer( new QWidget ); From 41c688aa6825920db1d7820a6f07c11b40db1c60 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Wed, 9 Jan 2013 15:34:44 +0100 Subject: [PATCH 4/5] style & capitalization fixes --- .../playlist/dynamic/echonest/EchonestControl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index c1426af53..e2fd388e3 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -553,7 +553,7 @@ Tomahawk::EchonestControl::updateData() QString songType = combo->currentText().toLower(); if ( match->currentText() == "is not" ) - songType.append(":false"); + songType.append( ":false" ); m_data.first = Echonest::DynamicPlaylist::SongType; m_data.second = songType; @@ -654,7 +654,7 @@ Tomahawk::EchonestControl::updateWidgetsFromData() if ( match && combo ) { match->setCurrentIndex( match->findData( m_matchData )); - QString songType = m_data.second.toString().split(":").at(0); + QString songType = m_data.second.toString().split( ":" ).at( 0 ); combo->setCurrentIndex( combo->findData( songType ) ); } } @@ -906,9 +906,9 @@ Tomahawk::EchonestControl::calculateSummary() Q_ASSERT( qobject_cast< QComboBox* >( m_match.data() ) ); QString isOrIsNot = qobject_cast< QComboBox* >( m_match.data() )->currentText().toLower(); if ( isOrIsNot == "is" ) - summary = tr( "where Song Type is %1" ).arg( text ); + summary = tr( "where song type is %1" ).arg( text ); else - summary = tr( "where Song Type is not %1" ).arg( text ); + summary = tr( "where song type is not %1" ).arg( text ); } m_summary = summary; From a8010e2bb4cc4c78d7d3c94a1776fe6a8b2806cc Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Wed, 9 Jan 2013 16:23:41 +0100 Subject: [PATCH 5/5] don't compare any user visible strings --- .../playlist/dynamic/echonest/EchonestControl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp index e2fd388e3..61d25aaa1 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestControl.cpp @@ -551,8 +551,8 @@ Tomahawk::EchonestControl::updateData() m_matchString = match->currentText(); m_matchData = match->itemData( match->currentIndex() ).toString(); - QString songType = combo->currentText().toLower(); - if ( match->currentText() == "is not" ) + QString songType = combo->itemData( combo->currentIndex() ).toString(); + if ( match->currentIndex() == 1 ) songType.append( ":false" ); m_data.first = Echonest::DynamicPlaylist::SongType; @@ -904,8 +904,8 @@ Tomahawk::EchonestControl::calculateSummary() Q_ASSERT( !m_match.isNull() ); Q_ASSERT( qobject_cast< QComboBox* >( m_match.data() ) ); - QString isOrIsNot = qobject_cast< QComboBox* >( m_match.data() )->currentText().toLower(); - if ( isOrIsNot == "is" ) + QComboBox* combo = qobject_cast< QComboBox* >( m_match.data() ); + if ( combo->currentIndex() == 0 ) summary = tr( "where song type is %1" ).arg( text ); else summary = tr( "where song type is not %1" ).arg( text );