1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-22 13:43:11 +02:00

resolve playlists when set from a peer

update dynamic playlist to peers 3s after editing a control is finished
This commit is contained in:
Leo Franchi
2011-01-17 12:09:25 -05:00
parent b321bdea9a
commit 7b5fdef93a
5 changed files with 25 additions and 23 deletions

View File

@@ -26,6 +26,10 @@ Tomahawk::EchonestControl::EchonestControl( const QString& selectedType, const Q
: DynamicControl ( selectedType.isEmpty() ? "Artist" : selectedType, typeSelectors, parent ) : DynamicControl ( selectedType.isEmpty() ? "Artist" : selectedType, typeSelectors, parent )
{ {
setType( "echonest" ); setType( "echonest" );
m_editingTimer.setInterval( 3000 ); // 3 second timeout to edits
m_editingTimer.setSingleShot( true );
connect( &m_editingTimer, SIGNAL( timeout() ), this, SIGNAL( changed() ) );
updateWidgets(); updateWidgets();
} }
@@ -117,7 +121,8 @@ Tomahawk::EchonestControl::updateWidgets()
connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) ); connect( match, SIGNAL( currentIndexChanged(int) ), this, SLOT( updateData() ) );
connect( match, SIGNAL( currentIndexChanged(int) ), this, SIGNAL( changed() ) ); connect( match, SIGNAL( currentIndexChanged(int) ), this, SIGNAL( changed() ) );
connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) ); connect( input, SIGNAL( textChanged(QString) ), this, SLOT( updateData() ) );
connect( input, SIGNAL( editingFinished() ), this, SIGNAL( changed() ) ); connect( input, SIGNAL( editingFinished() ), this, SLOT( editingFinished() ) );
connect( input, SIGNAL( textEdited( QString ) ), &m_editingTimer, SLOT( stop() ) );
match->hide(); match->hide();
input->hide(); input->hide();
@@ -147,7 +152,8 @@ Tomahawk::EchonestControl::updateData()
} }
// fills in the current widget with the data from json or dbcmd (m_data.second and m_matchData) // fills in the current widget with the data from json or dbcmd (m_data.second and m_matchData)
void Tomahawk::EchonestControl::updateWidgetsFromData() void
Tomahawk::EchonestControl::updateWidgetsFromData()
{ {
if( selectedType() == "Artist" ) { if( selectedType() == "Artist" ) {
QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() ); QComboBox* combo = qobject_cast<QComboBox*>( m_match.data() );
@@ -159,3 +165,9 @@ void Tomahawk::EchonestControl::updateWidgetsFromData()
} }
} }
void
Tomahawk::EchonestControl::editingFinished()
{
qDebug() << Q_FUNC_INFO;
m_editingTimer.start();
}

View File

@@ -20,6 +20,7 @@
#include <echonest/Playlist.h> #include <echonest/Playlist.h>
#include "dynamic/DynamicControl.h" #include "dynamic/DynamicControl.h"
#include <QTimer>
namespace Tomahawk namespace Tomahawk
{ {
@@ -49,6 +50,7 @@ public slots:
private slots: private slots:
void updateData(); void updateData();
void editingFinished();
private: private:
void updateWidgets(); void updateWidgets();
@@ -61,6 +63,8 @@ private:
QString m_matchData; QString m_matchData;
QString m_matchString; QString m_matchString;
QTimer m_editingTimer;
Echonest::DynamicPlaylist::PlaylistParamData m_data; Echonest::DynamicPlaylist::PlaylistParamData m_data;
friend class EchonestGenerator; friend class EchonestGenerator;

View File

@@ -30,7 +30,6 @@ DynamicControlList::DynamicControlList()
: AnimatedWidget() : AnimatedWidget()
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_lastControlDirty( false )
{ {
init(); init();
} }
@@ -40,7 +39,6 @@ DynamicControlList::DynamicControlList( AnimatedSplitter* parent )
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_isLocal( true ) , m_isLocal( true )
, m_lastControlDirty( false )
{ {
init(); init();
} }
@@ -51,7 +49,6 @@ DynamicControlList::DynamicControlList( const geninterface_ptr& generator, const
, m_layout( new QVBoxLayout ) , m_layout( new QVBoxLayout )
, m_summaryWidget( 0 ) , m_summaryWidget( 0 )
, m_isLocal( isLocal ) , m_isLocal( isLocal )
, m_lastControlDirty( false )
{ {
init(); init();
setControls( generator, controls, m_isLocal ); setControls( generator, controls, m_isLocal );
@@ -97,12 +94,14 @@ DynamicControlList::setControls( const geninterface_ptr& generator, const QList<
m_controls << new DynamicControlWidget( generator->createControl(), false, false, false, isLocal, this ); m_controls << new DynamicControlWidget( generator->createControl(), false, false, false, isLocal, this );
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) ); connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
} else } else
{ {
foreach( const dyncontrol_ptr& control, controls ) { foreach( const dyncontrol_ptr& control, controls ) {
m_controls << new DynamicControlWidget( control, false, false, false, isLocal, this ); m_controls << new DynamicControlWidget( control, false, false, false, isLocal, this );
connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) ); connect( m_controls.last(), SIGNAL( addNewControl() ), this, SLOT( addNewControl() ) );
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
} }
} }
onShown( this ); onShown( this );
@@ -155,7 +154,6 @@ void DynamicControlList::addNewControl()
connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) ); connect( m_controls.last(), SIGNAL( removeControl() ), this, SLOT( removeControl() ) );
connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) ); connect( m_controls.last(), SIGNAL( changed() ), this, SLOT( controlChanged() ) );
m_lastControlDirty = false;
emit controlsChanged(); emit controlsChanged();
} }
@@ -181,19 +179,10 @@ void DynamicControlList::controlChanged()
Q_ASSERT( sender() && qobject_cast<DynamicControlWidget*>(sender()) ); Q_ASSERT( sender() && qobject_cast<DynamicControlWidget*>(sender()) );
DynamicControlWidget* widget = qobject_cast<DynamicControlWidget*>(sender()); DynamicControlWidget* widget = qobject_cast<DynamicControlWidget*>(sender());
if( !widget->control()->input().isEmpty() ) emit controlChanged( widget->control() );
m_lastControlDirty = true;
emit controlChanged( qobject_cast<DynamicControlWidget*>(sender())->control() );
} }
void DynamicControlList::paintEvent(QPaintEvent* ) void DynamicControlList::paintEvent(QPaintEvent* )
{ {
} }
bool DynamicControlList::lastControlDirty() const
{
return m_lastControlDirty;
}

View File

@@ -47,7 +47,6 @@ public:
virtual void paintEvent(QPaintEvent* ); virtual void paintEvent(QPaintEvent* );
bool lastControlDirty() const;
signals: signals:
void controlsChanged(); void controlsChanged();
void controlChanged( const Tomahawk::dyncontrol_ptr& control ); void controlChanged( const Tomahawk::dyncontrol_ptr& control );
@@ -68,7 +67,6 @@ private:
QList< DynamicControlWidget* > m_controls; QList< DynamicControlWidget* > m_controls;
QWidget* m_summaryWidget; QWidget* m_summaryWidget;
bool m_isLocal; bool m_isLocal;
bool m_lastControlDirty;
}; };
}; };

View File

@@ -150,7 +150,7 @@ DynamicWidget::onRevisionLoaded( const Tomahawk::DynamicPlaylistRevision& rev )
{ {
qDebug() << "DynamicWidget::onRevisionLoaded"; qDebug() << "DynamicWidget::onRevisionLoaded";
loadDynamicPlaylist( m_playlist ); loadDynamicPlaylist( m_playlist );
if( m_resolveOnNextLoad ) if( m_resolveOnNextLoad || !m_playlist->author()->isLocal() )
{ {
m_playlist->resolve(); m_playlist->resolve();
m_resolveOnNextLoad = false; m_resolveOnNextLoad = false;
@@ -279,16 +279,15 @@ void
DynamicWidget::controlsChanged() DynamicWidget::controlsChanged()
{ {
// save the current playlist // save the current playlist
// if( !m_controls->lastControlDirty() ) { if( m_controls->controls().size() == 1 && m_playlist->generator()->controls().at( 0 )->input() == QString() ) { // if there is only 1 empty control, remove it as it's the default created one
if( m_controls->controls().size() == 1 && m_controls->lastControlDirty() && m_playlist->generator()->controls().at( 0 )->input() == QString() ) {
m_playlist->generator()->removeControl( m_playlist->generator()->controls().last() ); m_playlist->generator()->removeControl( m_playlist->generator()->controls().last() );
} }
m_playlist->createNewRevision(); m_playlist->createNewRevision();
} }
void void
DynamicWidget::controlChanged(const Tomahawk::dyncontrol_ptr& control) DynamicWidget::controlChanged( const Tomahawk::dyncontrol_ptr& control )
{ {
m_playlist->createNewRevision();
} }