1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02:00

Only allow voting once; Show the user's set score if he has rated it over the server

This commit is contained in:
Leo Franchi
2011-10-19 19:31:26 -04:00
parent 52930918f2
commit 742f73f028
4 changed files with 46 additions and 16 deletions

View File

@@ -113,11 +113,10 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
return false; return false;
Attica::Content resolver = m_contentList[ index.row() ];
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
if ( role == Qt::EditRole ) if ( role == Qt::EditRole )
{ {
Attica::Content resolver = m_contentList[ index.row() ];
AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( resolver );
switch( state ) switch( state )
{ {
case AtticaManager::Uninstalled: case AtticaManager::Uninstalled:
@@ -141,6 +140,11 @@ GetNewStuffModel::setData( const QModelIndex &index, const QVariant &value, int
}; };
} else if ( role == RatingRole ) } else if ( role == RatingRole )
{ {
// For now only allow rating if a resolver is installed!
if ( state != AtticaManager::Installed && state != AtticaManager::NeedsUpgrade )
return false;
if ( AtticaManager::userHasRated( resolver ) )
return false;
m_contentList[ index.row() ].setRating( value.toInt() * 20 ); m_contentList[ index.row() ].setRating( value.toInt() * 20 );
AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] ); AtticaManager::instance()->uploadRating( m_contentList[ index.row() ] );
} }

View File

@@ -151,7 +151,20 @@ AtticaManager::pathFromId( const QString& resolverId ) const
void void
AtticaManager::uploadRating( const Content& c ) AtticaManager::uploadRating( const Content& c )
{ {
m_resolverStates[ c.id() ].rating = c.rating(); m_resolverStates[ c.id() ].userRating = c.rating();
for ( int i = 0; i < m_resolvers.count(); i++ )
{
if ( m_resolvers[ i ].id() == c.id() )
{
Attica::Content atticaContent = m_resolvers[ i ];
atticaContent.setRating( c.rating() );
m_resolvers[ i ] = atticaContent;
break;
}
}
TomahawkSettings::instance()->setAtticaResolverStates( m_resolverStates );
PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() ); PostJob* job = m_resolverProvider.voteForContent( c.id(), (uint)c.rating() );
connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) ); connect( job, SIGNAL( finished( Attica::BaseJob* ) ), job, SLOT( deleteLater() ) );
@@ -161,6 +174,12 @@ AtticaManager::uploadRating( const Content& c )
emit resolverStateChanged( c.id() ); emit resolverStateChanged( c.id() );
} }
bool
AtticaManager::userHasRated( const Content& c ) const
{
return m_resolverStates[ c.id() ].userRating != -1;
}
void void
AtticaManager::providerAdded( const Provider& provider ) AtticaManager::providerAdded( const Provider& provider )
@@ -231,14 +250,20 @@ AtticaManager::syncServerData()
foreach ( const QString& id, m_resolverStates.keys() ) foreach ( const QString& id, m_resolverStates.keys() )
{ {
Resolver r = m_resolverStates[ id ]; Resolver r = m_resolverStates[ id ];
foreach ( const Content& upstream, m_resolvers ) for ( int i = 0; i < m_resolvers.size(); i++ )
{ {
Attica::Content upstream = m_resolvers[ i ];
// same resolver // same resolver
if ( id != upstream.id() ) if ( id != upstream.id() )
continue; continue;
// Update our rating with the server's idea of rating // Update our rating with the server's idea of rating if we haven't rated it
m_resolverStates[ id ].rating = upstream.rating(); if ( m_resolverStates[ id ].userRating != -1 )
{
upstream.setRating( m_resolverStates[ id ].userRating );
m_resolvers[ i ] = upstream;
}
// DO we need to upgrade? // DO we need to upgrade?
if ( ( r.state == Installed || r.state == NeedsUpgrade ) && if ( ( r.state == Installed || r.state == NeedsUpgrade ) &&
!upstream.version().isEmpty() ) !upstream.version().isEmpty() )

View File

@@ -48,13 +48,13 @@ public:
struct Resolver { struct Resolver {
QString version, scriptPath; QString version, scriptPath;
int rating; // 0-100 int userRating; // 0-100
ResolverState state; ResolverState state;
QPixmap* pixmap; QPixmap* pixmap;
Resolver( const QString& v, const QString& path, int r, ResolverState s ) Resolver( const QString& v, const QString& path, int userR, ResolverState s )
: version( v ), scriptPath( path ), rating( r ), state( s ), pixmap( 0 ) {} : version( v ), scriptPath( path ), userRating( userR ), state( s ), pixmap( 0 ) {}
Resolver() : state( Uninstalled ), pixmap( 0 ) {} Resolver() : userRating( -1 ), state( Uninstalled ), pixmap( 0 ) {}
}; };
typedef QHash< QString, AtticaManager::Resolver > StateHash; typedef QHash< QString, AtticaManager::Resolver > StateHash;
@@ -90,6 +90,7 @@ public:
QString pathFromId( const QString& resolverId ) const; QString pathFromId( const QString& resolverId ) const;
void uploadRating( const Attica::Content& c ); void uploadRating( const Attica::Content& c );
bool userHasRated( const Attica::Content& c ) const;
static bool removeDirectory( const QString& dir ); static bool removeDirectory( const QString& dir );

View File

@@ -45,7 +45,7 @@ inline QDataStream& operator<<(QDataStream& out, const AtticaManager::StateHash&
foreach( const QString& key, states.keys() ) foreach( const QString& key, states.keys() )
{ {
AtticaManager::Resolver resolver = states[ key ]; AtticaManager::Resolver resolver = states[ key ];
out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << (quint32)resolver.rating; out << key << resolver.version << resolver.scriptPath << (qint32)resolver.state << resolver.userRating;
} }
return out; return out;
} }
@@ -59,13 +59,13 @@ inline QDataStream& operator>>(QDataStream& in, AtticaManager::StateHash& states
for ( uint i = 0; i < count; i++ ) for ( uint i = 0; i < count; i++ )
{ {
QString key, version, scriptPath; QString key, version, scriptPath;
qint32 state, rating; qint32 state, userRating;
in >> key; in >> key;
in >> version; in >> version;
in >> scriptPath; in >> scriptPath;
in >> state; in >> state;
in >> rating; in >> userRating;
states[ key ] = AtticaManager::Resolver( version, scriptPath, rating, (AtticaManager::ResolverState)state ); states[ key ] = AtticaManager::Resolver( version, scriptPath, userRating, (AtticaManager::ResolverState)state );
} }
return in; return in;
} }
@@ -183,7 +183,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion )
addSipPlugin( "sipzeroconf_legacy" ); addSipPlugin( "sipzeroconf_legacy" );
} else if ( oldVersion == 3 ) } else if ( oldVersion == 3 )
{ {
if ( contains( "script/atticaResolverStates" ) ) if ( contains( "script/atticaresolverstates" ) )
{ {
// Do messy binary upgrade. remove attica resolvers :( // Do messy binary upgrade. remove attica resolvers :(
setValue( "script/atticaresolverstates", QVariant() ); setValue( "script/atticaresolverstates", QVariant() );